Python urllib2爬虫豆瓣小说名称和评分
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>