免翻墙上google(python3.3版)已打包

2015-03-06 0 935
免翻墙上google(python3.3版)已打包
#-*-coding:utf-8-*-
#python3.3.5
import urllib.request,os,time,platform,shutil,re
url='http://www.360kb.com/kb/2_150.html'
_360kb = urllib.request.urlopen(url)
status = _360kb.code
if platform.uname()[0]=='Windows':
    file = r'c:\windows\system32\drivers\etc\hosts'
else:
    file = r'/etc/hosts'
print('-------------------------------------------')
print('-----                                 -----')
print('-----                                 -----')
if status == 200 :
    html = str(_360kb.read())
    a = html.find('#google-hosts-2015')
    b = html.find('#google-hosts-2015-end')
    html = html[a:b]
    html = html.replace('<br />', '').replace('&nbsp;', '').replace('<span>', '').replace('</span>', '').replace('\\n', '\n')
   
    re_h = re.compile('</?\w+[^>]*>')#HTML标签
    html = re_h.sub('',html) #去掉HTML 标签
    shutil.copyfile(file, '%s.bak-%s'%(file, time.strftime('%Y%m%d%H%M%S')))
    output = open(file, 'w') 
    output .write(html)
    output .close()
    print('-----             执行成功            -----')
else:
    print('-----            执行失败             -----')
print('-----                                 -----')
print('-----                                 -----')
print('-------------------------------------------')
time.sleep(5)

遇见资源网 python 免翻墙上google(python3.3版)已打包 http://www.ox520.com/15154.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务