-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCrawlerDriver.py
41 lines (32 loc) · 1.15 KB
/
CrawlerDriver.py
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
#coding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
from TencentWeiboCrawler import TencentWeiboCrawler
from HexunWeiboCrawler import HexunWeiboCrawler
from SinaWeiboCrawler import SinaWeiboCrawler
class CrawlerDriver:
def __init__(self):
self.sid = None
def setWeiboCrawler(self, name, username=None, password=None):
parse_dict = {
'腾讯': TencentWeiboCrawler,
'和讯': HexunWeiboCrawler,
'新浪': SinaWeiboCrawler
}
if name == '腾讯':
self.weibo_crawler = parse_dict[name](username, password)
if self.sid:
self.weibo_crawler.sid = self.sid
else:
self.sid = self.weibo_crawler.getSid()
else:
self.weibo_crawler = parse_dict[name]()
def getWeibos(self, keyword, page, count):
return self.weibo_crawler.getWeibos(keyword, page, count)
if __name__ == '__main__':
wcd = CrawlerDriver()
wcd.setWeiboCrawler('腾讯', '腾讯帐号', '腾讯密码')
#wcd.setWeiboCrawler('新浪')
#wcd.setWeiboCrawler('和讯')
print wcd.getWeibos('比特币', 1, 1)