当前位置:网站首页 > 更多 > 编程开发 > 正文

[Python] 7行代码爬取本博客所有文章

作者:CC下载站 日期:2021-01-05 00:00:00 浏览:54 分类:编程开发

为了水篇博客,我也是尽力了。

如果报错,就新建一个文件夹abc

importrequests,parsel
foriinrange(1,37):
res=parsel.Selector(requests.get(f'https://pan.lanol.cn/page_{i}.html').text)
titles=res.xpath("//h2[@class='entry-title']/a/text()").extract()
forindex,valueinenumerate(res.xpath("//h2[@class='entry-title'][email protected]").extract()):
withopen("./abc/"+titles[index]+'.html','a+',encoding='utf8')asf:
f.write(parsel.Selector(requests.get(value).text).xpath("//div[@class='single-content']").extract_first())

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯