forked from justzx2011/openyoudao
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fusionyoudao.py
31 lines (31 loc) · 1.33 KB
/
fusionyoudao.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
from BeautifulSoup import BeautifulSoup
import os
import gl
import re
import popen2
def reconstruct():
print "start fusionyoudao"
soup = BeautifulSoup(open(gl.origindir))
head=open(gl.headyoudao,'r')
result = soup.find('div',{"id":"results"})
#sousuo = soup.find('form',{"id":"f"})
#sousuo = str(sousuo).replace("action=\"/search\"","action=\"http://dict.youdao.com/search\"")
#result = str(result).replace("href=\"/example/","href=\"http://dict.youdao.com/example/")
#os.system("echo "" > cache/result.html")
f_tar=open(gl.resultdir,'w+')
print >> f_tar,"<html>"
print >> f_tar,head.read()
print >> f_tar,"<body>"
#print >> f_tar,"\n"
#print >> f_tar,"<div class=\"c-header\">"
#print >> f_tar,sousuo
#print >> f_tar,"</div>"
print >> f_tar,result
print >> f_tar,"</body></html>"
f_tar.close()
head.close()
os.system("sed -i -e 's/action=\"\/search/action=\"http:\/\/dict.youdao.com\/search/g' \'"+ gl.resultdir + "\'")
os.system("sed -i -e 's/href=\"\/example/href=\"http:\/\/dict.youdao.com\/example/g' \'"+ gl.resultdir + "\'")
#os.system("sed -i -e 's/href=\"\/simplayer.swf/href=\"http:\/\/dict.youdao.com\/simplayer.swf/g' \'"+ gl.resultdir + "\'")
print "fusionyoudao completed"
#os.system("sed -i -e 's/<\/div><\/div><\/div>/ /g' cache/result.html")