Python网络爬虫(五):b站弹幕

04-10 阅读 0评论

        上一篇对b站的视频评论爬取进行了探讨,这一篇是弹幕。直接上代码:

Python网络爬虫(五):b站弹幕,Python网络爬虫(五):b站弹幕,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,Python,爬虫,网络,第1张
(图片来源网络,侵删)
import csv
import json
import re
import chardet
import requests
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 SLBrowser/8.0.1.3162 SLBChan/105'}
# 对爬取的页面内容进行json格式处理
def get_text(url):
    res = requests.get(url=url, headers=headers)
    res.encoding = chardet.detect(res.content)['encoding']  # 统一字符编码
    res = res.text
    data = json.loads(res)  # json格式化
    return data
def get_cid(bv):
    url_1 = 'https://api.bilibili.com/x/player/pagelist?bvid={}'.format(bv)
    response = get_text(url_1)
    cid = response['data'][0]['cid']  # 获取cid
    return cid
def get_content_list(cid):
    content_list = []
    url = f'https://comment.bilibili.com/{cid}.xml'
    r2 = requests.ge
Python网络爬虫(五):b站弹幕,Python网络爬虫(五):b站弹幕,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,Python,爬虫,网络,第2张
(图片来源网络,侵删)
Python网络爬虫(五):b站弹幕,Python网络爬虫(五):b站弹幕,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,Python,爬虫,网络,第3张
(图片来源网络,侵删)

免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,人围观)

还没有评论,来说两句吧...

目录[+]