Skip to content

KeithYue/weibo-keywords-crawler

Repository files navigation

weibo-keywords-crawler

微博搜索爬虫,提供搜索关键字,爬取关键字相关内容的微博和评论信息。

更新说明

  • 使用手动输入验证码的方式。目前爬虫有两处需要验证码:1,登陆时。2,搜索过于频繁时。爬虫当需要填写验证码的时候,会自动下载验证码并且使用本机默认的图像查看工具载入验证码,窗口会自动弹出。这时,只要根据终端的提示输入验证码即可。爬虫将会继续
  • 增加OAuth2.0 微博评论的爬取。

问题反馈

在[https://github.com/KeithYue/weibo-keywords-crawler/issues] (https://github.com/KeithYue/weibo-keywords-crawler/issues) 下面开一个Issue, assign 给我。

运行环境和相关依赖

安装依赖

  • pip install -r requirements.txt -i http://pypi.v2ex.com/simple
  • 安装phantomJS, 并且添加到系统PATH中。

使用方法

  1. git clone https://github.com/KeithYue/weibo-keywords-crawler.git.
  2. cd weibo-keywords-crawler
  3. 配置keyowords.txt: 添加需要查询的关键字, 每行一个,如果是多关键词查询,每行用空格分开即可。
  4. 配置passwd.txt: 配置爬虫所需要的用户名和密码,每行一个,用户名和密码用空格分开。
  5. 运行python main.py: 启动爬虫,结果将存入result文件夹中。
  6. 爬虫日志会放在./weibo_crawler.log中,若需要动态查看爬虫行为:'tail -f ./weibo_crawler.log'

主要提供了WeiboCrawler类,用来进行微博搜索。

from weibo_crawler import WeiboCrawler

def main():
    wc = WeiboCrawler('大数据', '***', '***') # 三个参数:关键词(可以用空格分开),爬虫使用的用户名,爬虫使用的密码
    wc.crawl(page_count=1, comments = True) # page_count:获取结果的总页数, 默认为1,最高为50。comments:是否抓取评论数据,默认为False
    wc.save() # 存储结果
    return

if __name__ == '__main__':
    main()

运行Demo

python main.py。结果将存入resutls文件夹。

数据格式

注意事项

  • 该类只提供一次关键词的搜索,如果系统并行进行关键词的搜索,则需要自己编写多线程/进程的程序。
  • 由于目前不支持机器自动识别验证码,所以需要验证码时程序会自动载入并且使用图片查看工具进行显示,所以目前爬虫不能在没有GUI界面的server上运行。
  • 由于搜索结果最多有五十页,每页最多20条微博,所以对于每个关键词,每次执行最多只能获取1000条微博。

About

Crawl the related sina weibo content using the keywords, and save the results to txt file for future use.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages