首页 > 代码库 > Python urllib2爬虫豆瓣小说名称和评分

Python urllib2爬虫豆瓣小说名称和评分

#-*- coding:utf-8 -*-
import urllib2
import re

url = https://book.douban.com/tag/%E5%B0%8F%E8%AF%B4
request = urllib2.Request(url)
urlopen = urllib2.urlopen(request)
content = urlopen.read()
reg_0 = re.findall(rtitle.+"\s*on, content)
reg_1 = re.findall(rrating_nums">.*<, content)
for title,score in zip(reg_0,reg_1):
    title = re.split(r",title)
    score = re.split(r>|<,score)
    print title[1],score[1]



#<span class="rating_nums">8.6</span>

 

Python urllib2爬虫豆瓣小说名称和评分