免翻墙上google(python3.3版)已打包
发布时间:2020-12-17 17:24:11 所属栏目:Python 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #-*-coding:utf-8-*-#python3.3.5import urllib.request,os,time,platform,shutil,reurl='http://www.360kb.com/kb/2_150.html'_360kb = urllib.reque
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 #-*-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:windowssystem32driversetchosts' 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(' ','').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) 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |