-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCrawler.py
More file actions
55 lines (41 loc) · 1.22 KB
/
Crawler.py
File metadata and controls
55 lines (41 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
reload(sys)
# if(sys.platform == 'win32'):
# encoding = "gb2312"
# else:
# encoding = "utf8"
sys.setdefaultencoding("utf8")
try:
import SinaAPI
except ImportError, e:
print 'check module error:', e
exit()
def read_keywords():
keywords = list()
fp = open("./keywords")
line = fp.readline().strip()
while(line):
keywords.append(line)
line = fp.readline().strip()
fp.close()
return keywords;
def main():
#if(len(sys.argv) < 2):
# print "python ./Crawler keyword user/weibo"
#keyword = sys.argv[1].decode('gbk').encode("utf8")
#search_type = sys.argv[2]
#weibo_api = SinaAPI.WeiboSearchCrawler()
#weibo_api.gsearch(keyword=keyword)
keywords = read_keywords()
for keyword in keywords:
print "搜索关键词: %s" % keyword
#搜索微博用户
user_api = SinaAPI.UserSearchCrawler()
user_api.search(keyword=keyword)
#搜索微博
weibo_api = SinaAPI.WeiboSearchCrawler()
weibo_api.gsearch(keyword=keyword, pages=2)
if __name__ == '__main__':
main()