forked from kenshin17/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getuser_nhattao.py
57 lines (51 loc) · 1.22 KB
/
getuser_nhattao.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
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import urllib2
import threading
from time import time
import redis
'''
@author: k
'''
#f1 = open("user_nhattao/user_nhattao1.txt",'a')
r = redis.StrictRedis(host='localhost', port=6379, db=0)
start_time = time()
#---------------------
#function get_user
def get_user(url):
try:
res = urllib2.urlopen(url)
patten = ''
for i in res:
if re.search(r'<title>',i.strip()):
patten = i.strip().split(" ")
except Exception, e:
patten = ''
try:
return patten[0][7:]
except Exception, e:
return ""
#---------------------
#function run_getuser
#last user: 2251361
# def run_getuser(start_user,end_user,f_write):
# for i in range(start_user,end_user):
# url = "https://nhattao.com/members/"+str(i)
# if get_user(url):
# f_write.write(get_user(url)+"\n")
#---------------------
threads = []
for i in range(8000,10000):
url = "https://nhattao.com/members/"+str(i)
t = threading.Thread(target=get_user, args=(url,))
if t:
threads.append(t)
t.start()
r.set(i,get_user(url))
#---------------------
end_time = time()
time_process = end_time - start_time
print "Time time process: ", time_process
#
#threading.Thread(target=run_getuser,args=(5000, 5500, f1),).start()