scrapy 想实现爬取下一页的功能,但是”下一页“按钮并没有指向一个href。想请教如何实现爬取到下一页的功能
网址:https://chl.cn/?lishi

python scrapy爬虫如果想要下一页但是没有href
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
关注
你要模拟参数,具体代码如下:
import http.client conn = http.client.HTTPSConnection("chl.cn") #page 5 #submit 下一页 payload = 'page=5&submit=%E4%B8%8B%E4%B8%80%E9%A1%B5&str=' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Host': 'chl.cn', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded' } conn.request("GET", "/?lishi", payload, headers) res = conn.getresponse() data = res.read() print(data) print(data.decode("utf-8"))
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用