Python爬虫正则表达爬取b站所有动漫的评分

网友投稿 248 2022-09-06


Python爬虫正则表达爬取b站所有动漫的评分

import requestsimport reimport csvwq=1while(wq<163): dat={ "season_version":"-1", "spoken_language_type":"-1", "area":"-1", "is_finish":"-1", "copyright":"-1", "season_status":"-1", "season_month":"-1", "year":"-1", "style_id":"-1", "order":"4", "st":"1", "sort":"0", "page":f"{wq}", "season_type":"1", "pagesize":"20", "type":"1" } header={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36" } f=open("pingfen.csv",mode="a",encoding="utf-8",newline='') csvwriter=csv.writer(f) url=" resp=requests.get(url,params=dat,headers=header) print(resp.text) obj=re.compile(r'"cover":"(?P.*?)","index_show":"(?P.*?)","is_finish.*?ink":"(?P.*?)","media_id.*?order":"(?P.*?)","order_type".*?"title":"(?P.*?)","title_icon"',re.S) result=obj.finditer(resp.text) wq=wq+1 for i in result: # print(i.group("photo")) # print(i.group("jishu")) # print(i.group("link")) # print(i.group("order")) # print(i.group("name")) dic = i.groupdict() csvwriter.writerow(dic.values())f.close()print("over")# with open("mybaidu.txt",mode="w",encoding="utf-8") as f:# f.write(resp.text)# print("over")

正则表达相关参数:

爬取结果存入文件下

包含动漫名,图片,链接,综合评分,动画名

网上找的b站数据爬取基本都用不了,爬取不了b站综合评分,就自己学习写了个正则表达,毕设都整完了,这个功能就没加进去,还是时间不够没法学习


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:bs4爬虫(bs4爬虫爬取网页Python数据导入excel)
下一篇:Spring事务处理Transactional,锁同步和并发线程
相关文章

 发表评论

暂时没有评论,来抢沙发吧~