-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
43 lines (33 loc) · 1 KB
/
main.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
42
43
#!/usr/bin/env python
#coding=utf-8
from urllib2 import URLError
import time
from log import logger
from crawler import UserCrawler
from fetcher import CnFetcher
def local(uids=[]):
fetcher = CnFetcher()
fetcher.login()
connection_error = False
while len(uids) > 0 or connection_error:
if not connection_error:
uid = uids.pop()
try:
crawler = UserCrawler(uid, fetcher)
crawler.run()
connection_error = False
except URLError, e:
logger.exception(e)
connection_error = True
time.sleep(10)
if __name__ == "__main__":
import argparse
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
parser = argparse.ArgumentParser('Task to crawl sina weibo.')
parser.add_argument('uids', metavar="uids", type=str, nargs="*",
help="uids to crawl")
args = parser.parse_args()
uids = args.uids
local(uids)