免翻墙上google(python3.3版)已打包,,#-*-coding:u
文章由Byrx.net分享于2019-03-23 04:03:50
免翻墙上google(python3.3版)已打包,,#-*-coding:u
#-*-coding:utf-8-*-#python3.3.5import urllib.request,os,time,platform,shutil,reurl='http://www.360kb.com/kb/2_150.html'_360kb = urllib.request.urlopen(url)status = _360kb.codeif 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)
评论关闭