All Projects → cgDeepLearn → BilibiliCrawler

cgDeepLearn / BilibiliCrawler

Licence: GPL-3.0 License
🌀 crawl bilibili user info and video info for data analysis | BiliBili爬虫

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to BilibiliCrawler

Iclr2020 Openreviewdata
Script that crawls meta data from ICLR OpenReview webpage. Tutorials on installing and using Selenium and ChromeDriver on Ubuntu.
Stars: ✭ 426 (+1604%)
Mutual labels:  crawler, data-analysis
TripAdvisor-Crawling-Suite
Fetching hotel data from TripAdvisor.
Stars: ✭ 17 (-32%)
Mutual labels:  crawler
bilibili-api-docs
bilibili-api 的开发文档
Stars: ✭ 19 (-24%)
Mutual labels:  bilibili-api
domfind
A Python DNS crawler to find identical domain names under different TLDs.
Stars: ✭ 22 (-12%)
Mutual labels:  crawler
php-google
Google search results crawler, get google search results that you need - php
Stars: ✭ 23 (-8%)
Mutual labels:  crawler
CoreMS
CoreMS is a comprehensive mass spectrometry software framework
Stars: ✭ 20 (-20%)
Mutual labels:  data-analysis
sse-option-crawler
SSE 50 index options crawler 上证50期权数据爬虫
Stars: ✭ 17 (-32%)
Mutual labels:  crawler
lostark-wait-notifier
🐤️ Lost Ark wait notifier
Stars: ✭ 38 (+52%)
Mutual labels:  crawler
data-analysis-using-python
Data Analysis Using Python: A Beginner’s Guide Featuring NYC Open Data
Stars: ✭ 81 (+224%)
Mutual labels:  data-analysis
TextGridTools
Read, write, and manipulate Praat TextGrid files with Python
Stars: ✭ 84 (+236%)
Mutual labels:  data-analysis
medium-stat-box
Practical pinned gist which show your latest medium status 📌
Stars: ✭ 29 (+16%)
Mutual labels:  crawler
demeter
Process and analyze X-ray Absorption Spectroscopy data using Feff and either Larch or Ifeffit.
Stars: ✭ 50 (+100%)
Mutual labels:  data-analysis
ptt-web-crawler
PTT 網路版爬蟲
Stars: ✭ 20 (-20%)
Mutual labels:  crawler
Sharingan
We will try to find your visible basic footprint from social media as much as possible - 😤 more sites is comming soon
Stars: ✭ 13 (-48%)
Mutual labels:  crawler
Guitar
A Simple and Efficient Distributed Multidimensional BI Analysis Engine.
Stars: ✭ 86 (+244%)
Mutual labels:  data-analysis
arachnod
High performance crawler for Nodejs
Stars: ✭ 17 (-32%)
Mutual labels:  crawler
Data-Analyst-Nanodegree
Kai Sheng Teh - Udacity Data Analyst Nanodegree
Stars: ✭ 42 (+68%)
Mutual labels:  data-analysis
sherlock
🔎 Find usernames across social networks.
Stars: ✭ 47 (+88%)
Mutual labels:  data-analysis
rworkshops
Materials for R Workshops
Stars: ✭ 43 (+72%)
Mutual labels:  data-analysis
visions
Type System for Data Analysis in Python
Stars: ✭ 136 (+444%)
Mutual labels:  data-analysis

BilibiliCrawler

  • crawl bilibili user info and video info for data analysis。
  • 爬取部分哔哩哔哩up主信息和up主投稿视频信息,用作数据处理与分析学习(不得用于商业和其他侵犯他人权益的用途)。
  • 采取了一定的反反爬策略。
  • Bilibili更改了用户页面的api, 用户抓取解析程序需要重构。

快速开始

  1. 拉取项目, git clone https://github.com/cgDeepLearn/BilibiliCrawler.git
  2. 进入项目主目录,安装虚拟环境crawlenv(请参考使用说明里的虚拟环境安装)。
  3. 激活环境并在主目录运行crawl,爬取结果将保存在data目录csv文件中。
source activate crawlenv
python initial.py file  # 初始化file模式
python crawl_user.py file 1 100  # file模式,1 100是开始、结束bilibili的uid
进入data目录查看抓取的数据,是不是很简单!
  • 如果需要使用数据库保存和一些其他的设置,请看下面的使用说明

使用说明

1. 拉取项目,

git clone https://github.com/cgDeepLearn/BilibiliCrawler.git

2. 进入项目主目录, 安装虚拟环境

  • 若已安装anaconda
conda create -n crawlenv python=3.6
source activate crawlenv  # 激活虚拟环境
pip install -r requirements.txt
  • 若使用virtualenv
virtualenv crawlenv
source crawlenv/bin/activate  # 激活虚拟环境,windows下不用source
pip install -r requirements.txt  # 安装项目依赖

3. 修改配置文件

  • 进入config目录,修改config.ini配置文件(默认使用的是postgresql数据库,如果你是使用的是postgresql,只需要将其中的参数替换成你的,下面其他的步骤可以忽略) 数据库配置选择其中一个你本地安装的即可,将参数更换成你的 如果你需要更自动化的数据库配置,请移步我的DB_ORM项目
[db_mysql]
user = test
password = test
host = localhost
port = 3306
dbname = testdb

[db_postgresql]
user = test
password = test
host = localhost
port = 5432
dbname = testdb
  • 然后修改conf.py中获取配置文件的函数
def get_db_args():
    """
    获取数据库配置信息
    """
    return dict(CONFIG.items('db_postgresql'))  # 如果安装的是mysql,请将参数替换为db_mysql
  • 进入db目录,修改basic.py的连接数据库的DSN
# connect_str = "postgresql+psycopg2://{}:{}@{}:{}/{}".format(kwargs['user'], kwargs['password'], kwargs['host'], kwargs['port'], kwargs['dbname'])
# 若使用的是mysql,请将上面的connect_str替换成下面的
connect_str = "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(kwargs['user'], kwargs['password'], kwargs['host'], kwargs['port'], kwargs['dbname'])
# sqlite3,mongo等请移步我的DB_ORM项目,其他一些数据库也将添加支持

4. 运行爬虫

  • 在主目录激活虚拟环境, 初次运行请执行
python initial.py db # db模式,file模式请将db换成file
# file模式会将抓取结果保存在data目录
# db模式会将数据保存在设置好的数据库中
# 若再次以db模式运行将会drop所有表后再create,初次运行后请慎重再次使用!!!
# 如果修改添加了表,并不想清空数据,请运行 python create_all.py
  • 开始抓取示例
python crawl_user.py db 1 10000 # crawl_user 抓取用户数据,db 保存在数据库中, 1 10000为抓取起止id
python crawl_video_ajax.py db 1 100 # crawl_video_ajax 抓取视频ajax信息保存到数据库中,
python crawl_user_video.py db 1 10000 #同时抓取user 和videoinfo
# 示例为uid从1到100的user如果有投稿视频则抓取其投稿视频的信息,
# 若想通过视频id逐个抓取请运行python crawl_video_by_aid.py db 1 1000
  • 爬取速率控制

程序内已进行了一些抓取速率的设置,但各机器cpu、mem不同抓取速率也不同,请酌情修改
太快太慢请修改各crawl中的sleepsec参数,ip会被限制访问频率,overspeed会导致爬取数据不全,
之后会添加运行参数speed(high, low),不用再手动配置速率

  • 日志

爬取日志在logs目录
user, video分别为用户和视频的爬取日志
storage为数据库日志 如需更换log格式,请修改logger模块

  • 后台运行

linux下运行python ......前面加上nohup,例如:

nohup python crawl_user db 1 10000

程序输出保存文件,默认会包存在主目录额nohup.out文件中,添加 > fielname就会保存在设置的文件中:

nohup python crawl_video_ajax.py db 1 1000 > video_ajaxup_1_1000.out  # 输出将保存在video_ajaxup_1_1000.out中
  • 更多

程序多线程使用的生产者消费者模式中产生了程序运行的状况的打印信息,类似如下

produce 1_1
consumed 1_1
...

如想运行更快,请在程序各项设置好后注释掉其中的打印程序

# utils/pcModels.py
print('[+] produce %s_%s' % (index, pitem))  # 请注释掉

print('[-] consumed %s_%s\n' % (index, data))  # 请注释掉

更多

项目是单机多线程,若想使用分布式爬取,请参考Crawler-Celery

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].