-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepower.py
More file actions
68 lines (62 loc) · 1.88 KB
/
Copy pathepower.py
File metadata and controls
68 lines (62 loc) · 1.88 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
56
57
58
59
60
61
62
63
64
65
66
67
68
#encoding=utf-8
import urllib, urllib2, json
import cookielib
from util import *
from Redis import *
import sys
from threading import Thread
import socket
from MysqlFuncs import *
from Spider import *
import getopt
def thread_run(num, redisdb, url, data):
print "num = %s start ..." % num
(sid, tid) = redisdb.getSession()
print "sid=[%s] tid=[%s]" % (sid, tid)
AccessURL(url, data,sid, tid)
print "thread num=[%s] end" % num
def Run(argv):
start = time.time()
print "==========begin to crawl[%s]==================================" % (time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
try:
opts, args = getopt.getopt(argv[1:], 'vm:', ['country=', 'platform=', 'limit=', 'threadnum=', 'type='])
except getopt.GetoptError, err:
print str(err)
print "parameter error"
sys.exit(2)
if len(opts) < 2:
print "parameter numbers error [%s]" % len(opts)
sys.exit(2)
country="USA"
url_type="traveltochina"
limit=10000
threadnum=100
run_type='normal'
for option, arg in opts:
if option in ('--country'):
country = arg
elif option in ('--platform'):
url_type = arg
elif option in ('--limit'):
limit = arg
elif option in ('--threadnum'):
threadnum = arg
elif option in ('--type'):
run_type=arg
else :
print 'unhandled option'
sys.exit(3)
print "country=%s, url_type=%s, limit=%s, threadnum=%s" % (country, url_type, limit, threadnum)
spider = Spider(country=country, url_type=url_type, limit=limit, threadnum=threadnum)
if run_type == 'normal':
spider.run()
else:
spider.run_book()
end = time.time()
elapse = end - start
print "=========end crawl[%s],elapse[%s]============================" % ((time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())), elapse)
if __name__ == '__main__':
reload(sys)
sys.setdefaultencoding('utf-8')
socket.setdefaulttimeout(600)
Run(sys.argv)