解決谷歌搜索技術(shù)文章時打不開網(wǎng)頁問題的python腳本
更新時間:2013年02月10日 10:59:30 作者:
在用谷歌在搜索技術(shù)文章時,總是時不時的打不開網(wǎng)頁,于是寫了一個python腳本,感覺用著還行,分享給大家
注意:Win7或者WIn8用戶要用管理員權(quán)限執(zhí)行。
項(xiàng)目地址: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()
項(xiàng)目地址:http://code.google.com/p/my-hosts-file/downloads
復(fù)制代碼 代碼如下:
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()
相關(guān)文章
Python3讀取和寫入excel表格數(shù)據(jù)的示例代碼
這篇文章主要介紹了Python3讀取和寫入excel表格數(shù)據(jù)的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06python實(shí)現(xiàn)簡單通訊錄管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡單通訊錄管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05python計(jì)算auc指標(biāo)實(shí)例
下面小編就為大家?guī)硪黄猵ython計(jì)算auc指標(biāo)實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07DRF跨域后端解決之django-cors-headers的使用
這篇文章主要介紹了DRF跨域后端解決之django-cors-headers的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01django框架實(shí)現(xiàn)模板中獲取request 的各種信息示例
這篇文章主要介紹了django框架實(shí)現(xiàn)模板中獲取request 的各種信息,結(jié)合實(shí)例形式分析了Django框架模板直接獲取request信息的相關(guān)配置與操作技巧,需要的朋友可以參考下2019-07-07Python從函數(shù)參數(shù)類型引出元組實(shí)例分析
這篇文章主要介紹了Python從函數(shù)參數(shù)類型引出元組,結(jié)合實(shí)例形式分析了Python函數(shù)定義與使用中常見的三種參數(shù)類型,并簡單分析了元組類型參數(shù)的使用,需要的朋友可以參考下2019-05-05解讀pandas交叉表與透視表pd.crosstab()和pd.pivot_table()函數(shù)
這篇文章主要介紹了pandas交叉表與透視表pd.crosstab()和pd.pivot_table()函數(shù)的用法,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-09-09