码迷,mamicode.com
首页 > 编程语言 > 详细

python爬虫

时间:2019-04-14 19:22:12      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:art   爬虫   read   page   from   ati   dal   url   star   

import re
from urllib.request import urlopen

def getPage(url):
response = urlopen(url)
return response.read().decode(‘utf-8‘)

def parsePage(s):
ret = re.findall(
‘<div class="item">.*?<div class="pic">.*?<em .*?>(?P<id>\d+).*?<span class="title">(?P<title>.*?)</span>‘
‘.*?<span class="rating_num" .*?>(?P<rating_num>.*?)</span>.*?<span>(?P<comment_num>.*?)评价</span>‘,s,re.S)
return ret

def main(num):
url = ‘https://movie.douban.com/top250?start=%s&filter=‘ % num
response_html = getPage(url)
ret = parsePage(response_html)
print(ret)

count = 0
for i in range(10): # 10页
main(count)
count += 25

 

python爬虫

标签:art   爬虫   read   page   from   ati   dal   url   star   

原文地址:https://www.cnblogs.com/Intermittent-psychosis/p/10706464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!