爬虫:import requests
from lxml import etree
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36’
}
fp = open(’./info.txt’, ‘a’, encoding=‘utf-8’)
for page in range(0, 226, 25):
url = ‘https://book.douban.com/top250?start={}’.format(page) # 翻页规则
response = requests.get(url, headers=headers)
html = response.text
htmls = etree.HTML(html)
book_name = htmls.xpath(’//div[@class=“pl2”]/a/@title’)
for i in book_name:
print(’《’ + i + ‘》’)
fp.write(’《’ + i + ‘》’ + ‘\n’)