-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phonetic.py
40 lines (33 loc) · 992 Bytes
/
Phonetic.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
import urllib.request
from multiprocessing import Pool
import re
import urllib.request as req
from urllib.parse import unquote
def search(e,url):
r = req.Request(url + e)
s = req.urlopen(r)
page = s.read().decode('utf-8')
# print(page)
print(1)
try:
v = re.search('>美\s+<span class="phonetic">([\S\W\]]+?)<', page)
# print(e + "\t" + v.group(1))
return e+' '+v.group(1)
except(AttributeError):
print("检查单词拼写" + e)
if __name__ == '__main__':
url = 'http://dict.youdao.com/w/eng/'
tone = []
with open('./a.txt', 'r') as a:
item = a.read().split('\n')
p = Pool(2)
for i in item:
res = p.apply_async(search, args=(i,url))
tone.append(res)
p.close()
p.join()
# for i in tone:
# print(str(i.get()))
with open('./b.txt','a+',encoding='utf-8') as b:
for i in tone:
b.write(str(i.get())+"\n")