代码如下:
# -*- coding: utf-8 -*
import requests,time
from lxml import etree
c = 0
for n in range(0,2):
url='https://book.douban.com/top250?start={}'.format(n*25)
data=requests.get(url).text
s=etree.HTML(data)
books=s.xpath('//*[@id="content"]/div/div[1]/div/table')
for i in books:
title=i.xpath('./tr/td[2]/div[1]/a/@title')[0]
score=i.xpath('./tr/td[2]/div[2]/span[2]/text()')[0]
simple=i.xpath('./tr/td[2]/p[2]/span/text()')
num=i.xpath('./tr/td[2]/div[2]/span[3]/text()')[0].strip('(').strip().strip(')').replace('\n','').strip()
num2 = i.xpath('./tr/td[2]/div[2]/span[3]/text()')[0]
href=i.xpath('./tr/td[2]/div[1]/a/@href')[0]
time.sleep(2)
c=c+1
if len(simple)>0:
p