手机
当前位置:查字典教程网 >脚本专栏 >python >解决谷歌搜索技术文章时打不开网页问题的python脚本
解决谷歌搜索技术文章时打不开网页问题的python脚本
摘要:注意:Win7或者WIn8用户要用管理员权限执行。项目地址:http://code.google.com/p/my-hosts-file/d...

注意:Win7或者WIn8用户要用管理员权限执行。

项目地址:http://code.google.com/p/my-hosts-file/downloads

复制代码 代码如下:

import urllib

import os

import shutil

hostspath = "C:WindowsSystem32driversetc"

savepath = hostspath + "hostsave"

def download_hosts(url = "http://my-hosts-file.googlecode.com/svn/trunk/hosts"):

os.chdir(hostspath)

if os.getcwd() != hostspath:

print("Switch Dir to System32 Error,check permission!npwd:"+os.getcwd())

exit()

try:

urllib.urlretrieve(url, "hostsave")

except:

print 't Error when retrieveing hosts file from url: ', url

def backup_hosts():

shutil.copy("hosts","hosts.bak")

def replace_hosts():

shutil.copy("hostsave", "hosts")

print("Replace original hosts file finished, then flush dns...")

os.remove(savepath)

os.system("ipconfig /flushdns")

def main():

download_hosts()

backup_hosts()

replace_hosts()

if __name__ == '__main__':

main()

【解决谷歌搜索技术文章时打不开网页问题的python脚本】相关文章:

centos系统升级python 2.7.3

python 动态获取当前运行的类名和函数名的方法

python self,cls,decorator的理解

使用python 获取进程pid号的方法

如何搜索查找并解决Django相关的问题

一篇不错的Python入门教程

如何运行Python程序的方法

Python 过滤字符串的技巧,map与itertools.imap

python抓取网页图片示例(python爬虫)

写了个监控nginx进程的Python脚本

精品推荐
分类导航