importrequestsimportreimportjsondefgetPage(url):
response=requests.get(url)returnresponse.textdefparsePage(s):
com=re.compile('
.*?
.*?
(?P\d+).*?(?P.*?)'
'.*?
.*?(?P.*?)评价',re.S)ret=com.finditer(s)for i inret:yield{"id":i.group("id"),"title":i.group("title"),"rating_num":i.group("rating_num"),"comment_num":i.group("comment_num"),
}defmain(num):
url='https://movie.douban.com/top250?start=%s&filter='%num
response_html=getPage(url)
ret=parsePage(response_html)print(ret)
f=open("move_info7","a",encoding="utf8")for obj inret:print(obj)
data=json.dumps(obj,ensure_ascii=False)
f.write(data+"\n")if __name__ == '__main__':
count=0for i in range(10):
main(count)
count+=25