简易版爬虫(豆瓣)
import requests
import re
def get_douban():
res_str = requests.get("https://movie.douban.com/top250?start=0&filter=")
return res_str.text
def run():
resong = get_douban()
obj = re.compile('<span class="title">(?P<name>.*?)</span>.*?<span>(?P<evaluate>.*?)</span>.*?'
'<p class="">\\n\s+(?P<director>.*?) ?', re.S)
ret = obj.finditer(resong)
return ret
def zuz():
for i in run():
yield{"name":i.group('name'),
"evaluate":i.group('evaluate'),
"director":i.group('director')
}
for i in zuz():
print(i)