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(r'title.+"\s*on', content)
reg_1 = re.findall(r'rating_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>

 

posted @ 2017-07-31 11:33  debuggor  阅读(170)  评论(0编辑  收藏  举报