爬虫|B站《啥是佩奇》弹幕词云
2019-01-23 本文已影响0人
kami1护
《啥是佩奇》小猪佩奇过大年
↑↑↑↑↑↑↑↑↑↑↑↑上面是一个B站视频链接,但是貌似没啥用???↑↑↑↑↑↑↑↑↑↑↑↑↑
1、源数据获取
B站弹幕有专门的API,只需要获取到对应的cid就行


编写爬虫获取弹幕,保存为csv文件

有意思的地方是,df.to_csv('peiqi.csv',encoding='utf_8')会乱码。在程序中能够正常输出中文,但是导出到文件后使用excel打开时出现中文乱码是因为excel能够正确识别用gb2312、gbk、gb18030或utf_8 with BOM (utf_8_sig)编码的中文,如果是utf_8 no BOM(utf_8)编码的中文文件,excel打开会乱码。

总弹幕有1756条,但是API只显示1000条,因此只爬取了1000条。只作练习,不多纠结,1000就1000吧
2、词云展示
使用pandas读取弹幕CSV文件,jieba分词,最后用wordcloud 生成词云matplotlib展示。


原图片

词云展示

词频top50的分词

“某些 上来” 什么鬼?“上来 说话我求” ??“说话我求 某些”???

证明stopwords很有必要!!!
额,顺便问一下,“硬核” 啥意思?