我是靠谱客的博主 虚拟茉莉,这篇文章主要介绍python 爬虫实战(一)爬取豆瓣图书top250,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import requests from lxml import etree with open('booktop250.txt','w',encoding='utf-8') as f: for i in range(0,226,25): url = 'https://book.douban.com/top250?start={}'.format(i) data = requests.get(url).text page = etree.HTML(data) file = page.xpath('//*[@id="content"]/div/div[1]/div/table') for div in file: title = div.xpath('./tr/td[2]/div[1]/a/@title') pf = div.xpath('./tr/td[2]/div[2]/span[2]/text()') words = div.xpath('./tr/td[2]/p[2]/span/text()') f.write("n""{}{}{}".format(title,pf,words)) print("ALL IS OVER!")

最后

以上就是虚拟茉莉最近收集整理的关于python 爬虫实战(一)爬取豆瓣图书top250的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部