脚本专栏 
首页 > 脚本专栏 > 浏览文章

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

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )
注意:Win7或者WIn8用户要用管理员权限执行。

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

复制代码 代码如下:
import urllib 
    import os 
    import shutil 

    hostspath = "C:\\Windows\\System32\\drivers\\etc" 
    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()
上一篇:flask中使用SQLAlchemy进行辅助开发的代码
下一篇:easy_install python包安装管理工具介绍
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网