爬虫爬小说
import requestsimport re
#name = input('请输入想要查找的小说的名字:')
params = {
'q':'无敌真寂寞'
}
headers = {
'Accept-Language': 'zh-CN',
'Cache-Control': 'no-cache',
'Connection': 'Keep-Alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363'
}
url = 'https://www.biduo.cc/search.php?'
res = requests.get(url=url,params=params,headers=headers)
html = res.text
# regular = re.compile('')
# m = regular.findall(html)
print(m)
想爬个小说,html就是查找那部小说的连接,但是找小说章节连接的正则表达式写不出来,有大佬能指点一下吗{:10_266:} 这样能爬到搜索榜一的小说详情页,看看有没有启发{:10_279:}
import requests
import bs4
import os
url = f'https://www.biduo.cc/search.php?q={input("请输入小说名:")}'
headers = {
'Accept-Language': 'zh-CN',
'Cache-Control': 'no-cache',
'Connection': 'Keep-Alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363'
}
res = requests.get(url,headers=headers)
s = bs4.BeautifulSoup(res.text,features="lxml")
xiaoshuo = s.find("h3",class_="result-item-title result-game-item-title") #找到 第一个 标签(即为搜索榜一) 找全部可用s.find_all
url_ = xiaoshuo.find("a").get ('href')# 在获得的标签中 继续找到 a 标签,并get 到 href 属性
print("https://www.biduo.cc" + url_) #加前缀
Wei_Jian_Xian 发表于 2020-8-22 02:51
这样能爬到搜索榜一的小说详情页,看看有没有启发
导入的os库没用{:10_261:} import requests
import re
#name = input('请输入想要查找的小说的名字:')
params = {
'q':'无敌真寂寞'
}
headers = {
'Accept-Language': 'zh-CN',
'Cache-Control': 'no-cache',
'Connection': 'Keep-Alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363'
}
url = 'https://www.biduo.cc/search.php?'
res = requests.get(url=url,params=params,headers=headers)
html = res.text
regular = re.compile('cpos="title".*?class')
m = regular.findall(html)
print(m)
在此基础上提取链接 Wei_Jian_Xian 发表于 2020-8-22 02:51
这样能爬到搜索榜一的小说详情页,看看有没有启发
我感受到了自己知识的贫瘠{:10_266:} 1q23w31 发表于 2020-8-22 07:51
在此基础上提取链接
谢谢大佬{:10_254:}
页:
[1]