|  | 
 
| 
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  复制代码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('')
# m = regular.findall(html)
print(m)
想爬个小说,html就是查找那部小说的连接,但是找小说章节连接的正则表达式写不出来,有大佬能指点一下吗
   
这样能爬到搜索榜一的小说详情页,看看有没有启发   复制代码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_) #加前缀
 | 
 |