-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail_craw.py
More file actions
88 lines (69 loc) · 1.78 KB
/
Copy pathEmail_craw.py
File metadata and controls
88 lines (69 loc) · 1.78 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import threading
import Queue
import urllib2
import time
import re
import gevent
from gevent import monkey;
monkey.patch_all()
monkey.patch_all()
emailqueue = Queue.Queue()
queue = Queue.Queue() # 队列
def getdata(url):
try:
data = urllib2.urlopen(url).read().decode('utf-8')
return data
except:
return "异常"
def getHtmlList():
url_list = []
for i in range(1, 47):
url = 'https://bbs.tianya.cn/m/post-140-393974-{}.shtml'.format(str(i))
print(url)
url_list.append(url)
return url_list
def getemail(data):
try:
mailregex = re.compile(
r"([0-9a-zA-Z.%+\-]+@[0-9a-zA-Z.\-]+\.[A-Za-z]{1,3})",
re.IGNORECASE)
mylist = mailregex.findall(data)
return mylist
except:
return []
# data=getdata(url)
# time.sleep(5)
# test='lingdianbing@sina.com'
# data=getdata(url)
# kk=getemail(data)
# print(kk)
email_list = []
def BFS(urllist):
for url in urllist:
queue.put(url)
while not queue.empty():
url = queue.get() # 取出url
pagedata = getdata(url)
emaillist = getemail(pagedata) # 抓取邮箱
if len(emaillist) != 0:
for email in emaillist:
print(email)
email_list.append(email)
for i in email_list:
emailqueue.put(i)
def saveEmail():
global emailqueue
mailfile = open("mail.txt", "wb")
while True:
time.sleep(3)
while not emailqueue.empty():
data = emailqueue.get()
mailfile.write(data + "\r\n")
mailfile.flush()
mailfile.close()
gevent.joinall(
[
gevent.spawn(BFS, getHtmlList()),
gevent.spawn(saveEmail),
]
)