Python爬虫正则表达爬取b站所有动漫的评分
2022/4/20 22:12:56
本文主要是介绍Python爬虫正则表达爬取b站所有动漫的评分,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import requests import re import csv wq=1 while(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="https://api.bilibili.com/pgc/season/index/result/#" resp=requests.get(url,params=dat,headers=header) print(resp.text) obj=re.compile(r'"cover":"(?P<photo>.*?)","index_show":"(?P<jishu>.*?)","is_finish.*?ink":"(?P<link>.*?)","media_id.*?order":"(?P<order>.*?)","order_type".*?"title":"(?P<name>.*?)","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站综合评分,就自己学习写了个正则表达,毕设都整完了,这个功能就没加进去,还是时间不够没法学习
这篇关于Python爬虫正则表达爬取b站所有动漫的评分的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享
- 2024-12-19Python资料:新手入门的全面指南
- 2024-12-19Python股票自动化交易实战入门教程
- 2024-12-19Python股票自动化交易入门教程