weibo-keywords-crawler

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

更新说明

问题反馈

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

运行环境和相关依赖

安装依赖

使用方法

  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文件夹。

数据格式

注意事项