GithubHelp home page GithubHelp logo

shenxiangzhuang / bilibili-comments-spider Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lsm2016/bilibili-lottery

1.0 0.0 1.0 4.73 MB

自动爬取B站某个视频的评论并抽奖

Python 100.00%
spider mysql-database bilibili python3

bilibili-comments-spider's Introduction

Bilibili-Comments-Spider

自动爬取B站某个视频及番剧所有剧集的评论. (改自Bilibili-Lottery)

暂时没有使用多线程或者多进程,测试时候大概10分钟可以抓取50000条数据。

结果展示

同时存入本地MySQL数据库和CSV文件, CSV格式如下。

[改进后]使用方法

Step1:

在dbhelper.py内修改你的MySQL相关参数

host = "localhost"
user = "username"
passwd = "********"
database = "databaseName"
comment_tablename = "Comments"

注意,我这里用MySQL8连接会报错,参考stackoverflow,设置一个登录选项解决。

此外,用mysql-connector时使用utf8mb4时会出现一堆错误...直接换pymysql了Orz

设置自动建表,注意如果已存在要修改下表名;然后插入程序是用的executemany,不然太慢了...

Step2:

获取单个视频评论

python get_comments.py -type video -url https://www.bilibili.com/video/av68680509\?spm_id_from\=333.851.b_7265706f7274466972737432.4

获取番剧所有剧集的评论

python get_comments.py -type play -url https://www.bilibili.com/bangumi/play/ep277026\?spm_id_from\=333.851.b_62696c695f7265706f72745f616e696d65.51

[拓展]番剧评论的抓取思路

使用python3 get_comments.py来获得B站评论,视频ID在文件内修改。 注意,对于上传的视频来说,一般URL格式为https://www.bilibili.com/video/avxxxxxxxx, 后面的视频IDxxxxxxxx也就是评论API中的oid

但是,对于番剧来说是其URL结尾格式并不是avxxxxxxxx,所以oid需要我们手动获取。 在每一部番的首页,如https://www.bilibili.com/bangumi/play/ep277026, 我们直接请求该地址,并直接用正则re.findall(r'"aid":(\d{8}),', s)获取所有的oid即可。

更新进程[已完成]

Rebuilding

bilibili-comments-spider's People

Contributors

shenxiangzhuang avatar sqy941013 avatar

Stargazers

 avatar

Forkers

xiangnanyue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.