豆瓣Top250

#coding=UTF-8
import urllib2
from bs4 import BeautifulSoup
# https://book.douban.com/top250?start=
time=0
sum=25
while time<=225:

    times=str(time)
    url="https://book.douban.com/top250?start="+times

    req = urllib2.urlopen(url)
    content = req.read()
    soup=BeautifulSoup(content,"html.parser")
    print "----------page=" + str(sum/25) + "-----------"
    for link in soup.find_all('div',{"class":"pl2"}):
        for text in link.find_all("a"):
            for none in text.stripped_strings:
                print none

        sum=sum+1
    time=time+25
print sum-25



推荐阅读更多精彩内容