微博搜索爬虫,提供搜索关键字,爬取关键字相关内容的微博和评论信息。
在[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
git clone https://github.com/KeithYue/weibo-keywords-crawler.git
.cd weibo-keywords-crawler
keyowords.txt
: 添加需要查询的关键字, 每行一个,如果是多关键词查询,每行用空格分开即可。passwd.txt
: 配置爬虫所需要的用户名和密码,每行一个,用户名和密码用空格分开。python main.py
: 启动爬虫,结果将存入result
文件夹中。./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()
python main.py
。结果将存入resutls文件夹。
一条微博一个文件,存放在.txt
文件中,utf-8
编码,数据格式为json
{ "repost_count": 11, "user_profile": "http://weibo.com/linewow", "keywords": [ "hkust" ], "comment_count": 2, "source_url": "http://weibo.com/1473473362/y2hsl74ca", "text": "【名校之旅】Hong Kong University of Science and Technology (HKUST) is the top 40 universities in the world in 2011. (Website:http://t.cn/aooAzL)香港科技大学,2011年世界大学排名前40.", "screen_name": "线话英语", "source": "微博 weibo.com", "created_at": { "$date": 1327431857000 }, "mid": "3405437611684426", "like_count": 0 }