国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

解決谷歌搜索技術文章時打不開網頁問題的python腳本

2020-02-23 04:49:28
字體:
來源:轉載
供稿:網友
注意: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 + "http://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()
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清河县| 浑源县| 平果县| 贺州市| 普兰店市| 道孚县| 德清县| 行唐县| 定南县| 遵义县| 镇巴县| 五家渠市| 嵊泗县| 南昌市| 长顺县| 镇赉县| 金门县| 新和县| 百色市| 都安| 怀集县| 瓮安县| 甘孜县| 榆树市| 顺昌县| 和平区| 揭东县| 米脂县| 拜泉县| 冷水江市| 南昌市| 滦南县| 新津县| 鹿泉市| 鲁甸县| 和静县| 抚松县| 江西省| 长垣县| 铜陵市| 微山县|