python爬虫
Posted 技术改变生活
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python爬虫相关的知识,希望对你有一定的参考价值。
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爬虫的主要内容,如果未能解决你的问题,请参考以下文章