当前位置 : 主页 > 编程语言 > python >

【Python】【爬虫】爬取豆瓣电影评分

来源:互联网 收集:自由互联 发布时间:2022-12-20
import requestsimport reimport csvurl = "https://movie.douban.com/top250"headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62"}resp = re
import requestsimport reimport csvurl = "https://movie.douban.com/top250"headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62"}resp = requests.get(url, headers=headers)page_content = resp.textobj = re.compile(r'<li>.*?<div class="item">.*?<span class="title">(?P<name>.*?)' r'</span>.*?<p class="">.*?<br>(?P<year>.*?) .*?<span ' r'class="rating_num" property="v:average">(?P<score>.*?)</span>.*?' r'<span>(?P<num>.*?)人评价</span>',re.S)result = obj.finditer(page_content)f=open("data.csv",mode="w")csvwriter = csv.writer(f)for it in result: #print(it.group("name")) # print(it.group("score")) # print(it.group("num")) # print(it.group("year").strip()) dic = it.groupdict() dic['year'] =dic['year'].strip() csvwriter.writerow(dic.values())f.close()print("over!")

【Python】【爬虫】爬取豆瓣电影评分_User

【Python】【爬虫】爬取豆瓣电影评分_Windows_02

【文章转自日本多IP站群服务器 http://www.558idc.com/japzq.html提供,感恩】
上一篇:【车辆动力】基于Matlab模拟停车动力学
下一篇:没有了
网友评论