All Projects → XWang20 → WeiboCrawler

XWang20 / WeiboCrawler

Licence: MIT License
无cookie版微博爬虫,可以连续爬取一个或多个新浪微博用户信息、用户微博及其微博评论转发。

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to WeiboCrawler

weibo-scraper
Simple Weibo Scraper
Stars: ✭ 50 (+11.11%)
Mutual labels:  crawler, weibo, weibo-spider
Weibo Crawler
新浪微博爬虫,用python爬取新浪微博数据,并下载微博图片和微博视频
Stars: ✭ 1,019 (+2164.44%)
Mutual labels:  crawler, weibo
Weibo Analyst
Social media (Weibo) comments analyzing toolbox in Chinese 微博评论分析工具, 实现功能: 1.微博评论数据爬取; 2.分词与关键词提取; 3.词云与词频统计; 4.情感分析; 5.主题聚类
Stars: ✭ 430 (+855.56%)
Mutual labels:  crawler, weibo
Lxspider
爬虫案例合集。包括但不限于《淘宝、京东、天猫、豆瓣、抖音、快手、微博、微信、阿里、头条、pdd、优酷、爱奇艺、携程、12306、58、搜狐、百度指数、维普万方、Zlibraty、Oalib、小说、招标网、采购网、小红书》
Stars: ✭ 60 (+33.33%)
Mutual labels:  crawler, weibo
Weibo Album Crawler
新浪微博相册大图多线程爬虫。
Stars: ✭ 83 (+84.44%)
Mutual labels:  crawler, weibo
Weibopicdownloader
免登录下载微博图片 爬虫 Download Weibo Images without Logging-in
Stars: ✭ 247 (+448.89%)
Mutual labels:  crawler, weibo
Decryptlogin
APIs for loginning some websites by using requests.
Stars: ✭ 1,861 (+4035.56%)
Mutual labels:  crawler, weibo
Weibo Topic Spider
微博超级话题爬虫,微博词频统计+情感分析+简单分类,新增肺炎超话爬取数据
Stars: ✭ 128 (+184.44%)
Mutual labels:  crawler, weibo
Sina Weibo Album Downloader
Multithreading download all HD photos / pictures from someone's Sina Weibo album.
Stars: ✭ 125 (+177.78%)
Mutual labels:  crawler, weibo
Weibo wordcloud
根据关键词抓取微博数据,再生成词云
Stars: ✭ 154 (+242.22%)
Mutual labels:  crawler, weibo
zeekEye
A Fast and Powerful Scraping and Web Crawling Framework.
Stars: ✭ 36 (-20%)
Mutual labels:  weibo, weibo-spider
ptt-web-crawler
PTT 網路版爬蟲
Stars: ✭ 20 (-55.56%)
Mutual labels:  crawler
flink-crawler
Continuous scalable web crawler built on top of Flink and crawler-commons
Stars: ✭ 48 (+6.67%)
Mutual labels:  crawler
gotosocial
Golang fediverse server.
Stars: ✭ 400 (+788.89%)
Mutual labels:  social-media
auto crawler ptt beauty image
Auto Crawler Ptt Beauty Image Use Python Schedule
Stars: ✭ 35 (-22.22%)
Mutual labels:  crawler
weibo-helper
mirai-console 插件开发计划
Stars: ✭ 21 (-53.33%)
Mutual labels:  weibo
domfind
A Python DNS crawler to find identical domain names under different TLDs.
Stars: ✭ 22 (-51.11%)
Mutual labels:  crawler
crawler
A simple and flexible web crawler framework for java.
Stars: ✭ 20 (-55.56%)
Mutual labels:  crawler
img-cli
An interactive Command-Line Interface Build in NodeJS for downloading a single or multiple images to disk from URL
Stars: ✭ 15 (-66.67%)
Mutual labels:  crawler
TaobaoAnalysis
练习NLP,分析淘宝评论的项目
Stars: ✭ 28 (-37.78%)
Mutual labels:  crawler

WeiboCrawler

项目说明

项目介绍

新浪微博是国内主要的社交舆论平台,对社交媒体中的数据进行采集是舆论分析的方法之一。本项目无需cookie,可以连续爬取一个或多个新浪微博用户信息、用户微博及其微博评论转发。

实例

抓取用户信息 user 抓取用户微博 mblog 抓取微博转发 Repost 抓取微博评论 comment

使用方法

拉取项目

$ git clone https://github.com/XWang20/WeiboCrawler.git

安装依赖

本项目Python版本为Python3.8

$ cd WeiboCrawler
$ python -m pip install -r requirements.txt

安装数据库(可选)

默认使用MongoDB数据库,可在settings.py中修改URL和数据库名,默认为localhost、weibo。

运行程序

基本程序

在命令行中运行以下命令:

抓取用户信息

$ scrapy crawl user

抓取用户微博

$ scrapy crawl mblog

抓取微博转发

$ scrapy crawl repost

抓取微博评论

$ scrapy crawl comment

自定义选项

  1. 关键词检索,需要将./WeiboCrawler/spiders/mblog.py中第28行代码替换为urls = init_url_by_search(),并在init_url_by_search()中增加关键词列表。

  2. 采集id和时间范围等信息可根据自己实际需要重写./WeiboCrawler/spiders/*.py中的start_requests函数。

  3. 输出方式:支持输出到mongo数据库中,或输出json或csv文件。

如果输出json或csv文件,需要在命令后加入-o *.json-o *.csv,例如:

$ scrapy crawl user -o user.csv

如果输出到mongo数据库中,需要将./WeiboCrawler/settings.py中 mongo 数据库的部分取消注释:

ITEM_PIPELINES = {
    'WeiboCrawler.pipelines.MongoPipeline': 400,
}
MONGO_URI = 'localhost'
MONGO_DB = 'weibo'
  1. 添加账号cookie:可在settings.py中添加默认头,或在start_request函数中添加。

  2. 默认下载延迟为3,可在settings.py修改DOWNLOAD_DELAY。

  3. 默认会爬取二级评论,如果不需要可以在comment.py中注释以下代码:

if comment['total_number']:
secondary_url = 'https://m.weibo.cn/comments/hotFlowChild?cid=' + comment['idstr']
yield Request(secondary_url, callback=self.parse_secondary_comment, meta={"mblog_id": mblog_id})

无cookie版限制的说明

  • 单用户微博最多采集200页,每页最多10条 限制可以通过添加账号cookie解决。

设置多线程和代理ip

  • 多线程:(单ip池或单账号不建议采用多线程) 在settings.py文件中将以下代码取消注释:
# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 100
# The download delay setting will honor only one of:
CONCURRENT_REQUESTS_PER_DOMAIN = 100
CONCURRENT_REQUESTS_PER_IP = 100
  • 代理ip池
  1. 填写middlewares.py中的fetch_proxy函数。
  2. settings.py文件中将以下代码取消注释:
# Enable or disable downloader middlewares
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {
    'WeiboCrawler.middlewares.IPProxyMiddleware': 100,
}
  1. settings.py文件中将DOWNLOAD_DELAY设置为0。
DOWNLOAD_DELAY = 0

字段说明

用户信息

  • _id: 用户ID
  • nick_name: 昵称
  • gender: 性别
  • brief_introduction: 简介
  • location: 所在地
  • mblogs_num: 微博数
  • follows_num: 关注数
  • fans_num: 粉丝数
  • vip_level: 会员等级
  • authentication: 认证,对于已认证用户该字段会显示认证信息
  • person_url: 首页链接

微博信息

  • _id: 微博id
  • bid: 微博bid
  • weibo_url: 微博URL
  • created_at: 微博发表时间
  • like_num: 点赞数
  • repost_num: 转发数
  • comment_num: 评论数
  • content: 微博内容
  • user_id: 发表该微博用户的id
  • tool: 发布微博的工具

转发信息

  • _id: 转发id
  • repost_user_id: 转发用户的id
  • content: 转发的内容
  • mblog_id: 转发的微博的id
  • created_at: 转发时间
  • source: 转发工具

评论信息

  • _id: 评论id
  • comment_user_id: 评论用户的id
  • content: 评论的内容
  • mblog_id: 评论的微博的id
  • created_at: 评论发表时间
  • like_num: 点赞数
  • root_comment_id: 根评论id,只有二级评论有该项
  • img_url: 图片地址
  • reply_comment_id: 评论的id,只有二级评论有该项

写在最后

本项目参考了dataabc/weibo-crawlernghuyong/WeiboSpider,感谢他们的开源。

欢迎为本项目贡献力量。欢迎大家提交PR、通过issue提建议(如新功能、改进方案等)、通过issue告知项目存在哪些bug、缺点等。

如有问题和交流,也欢迎联系我:[email protected]

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].