1 Star 0 Fork 0

RTsien / Code Fragments

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
更新google_hosts.py 895 Bytes
一键复制 编辑 原始数据 按行查看 历史
RTsien 提交于 2014-12-20 15:45 . new file
#coding=gbk
import urllib, BeautifulSoup
header = "#请不要在下面边添加任何条目,否则将在下次更新时失效!\n"
web=urllib.urlopen("http://www.360kb.com/kb/2_122.html")
soup=BeautifulSoup.BeautifulSoup(web.read())
new=soup.find(id="storybox")("p")[-1]
new_content=header+unicode(str(new),"utf8").replace("&nbsp;",' ').replace("<br />","")[5:-4]
#.text.replace("&nbsp;",'').replace("<>")
hosts=open("C:\Windows\System32\drivers\etc\hosts",'r')
old_content=hosts.read()
hosts.close()
hosts=open("C:\Windows\System32\drivers\etc\hosts",'w')
if old_content.find(header)<0:
if old_content[-1]!='\n\n\n':
content=old_content+'\n\n\n'+new_content
else:
content=old_content+new_content
else:
old_content=old_content[:old_content.find(header)]
content=old_content+new_content
hosts.write(content)
hosts.close()
C
1
https://gitee.com/rtsien/Code-Fragments.git
git@gitee.com:rtsien/Code-Fragments.git
rtsien
Code-Fragments
Code Fragments
master

搜索帮助