解決谷歌搜索技術(shù)文章時(shí)打不開網(wǎng)頁問題的python腳本
更新時(shí)間:2013年02月10日 10:59:30 作者:
在用谷歌在搜索技術(shù)文章時(shí),總是時(shí)不時(shí)的打不開網(wǎng)頁,于是寫了一個(gè)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)文章
Python反向傳播實(shí)現(xiàn)線性回歸步驟詳細(xì)講解
回歸是監(jiān)督學(xué)習(xí)的一個(gè)重要問題,回歸用于預(yù)測輸入變量和輸出變量之間的關(guān)系,特別是當(dāng)輸入變量的值發(fā)生變化時(shí),輸出變量的值也隨之發(fā)生變化?;貧w模型正是表示從輸入變量到輸出變量之間映射的函數(shù)2022-10-10
Python實(shí)現(xiàn)統(tǒng)計(jì)給定字符串中重復(fù)模式最高子串功能示例
這篇文章主要介紹了Python實(shí)現(xiàn)統(tǒng)計(jì)給定字符串中重復(fù)模式最高子串功能,涉及Python針對字符串的遍歷、排序、切片、運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下2018-05-05
python實(shí)現(xiàn)人臉檢測的簡單實(shí)例
這篇文章主要給大家介紹了關(guān)于python實(shí)現(xiàn)人臉檢測的相關(guān)資料,OpenCV?可以使用機(jī)器學(xué)習(xí)算法搜索圖像中的人臉,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-02-02
Pytorch基礎(chǔ)之torch.randperm的使用
這篇文章主要介紹了Pytorch基礎(chǔ)之torch.randperm的使用方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02
Python與AI分析時(shí)間序列數(shù)據(jù)
預(yù)測給定輸入序列中的下一個(gè)是機(jī)器學(xué)習(xí)中的另一個(gè)重要概念.本章為您提供有關(guān)分析時(shí)間序列數(shù)據(jù)的詳細(xì)說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助2022-05-05
詳解DBSCAN算法原理及其Python實(shí)現(xiàn)
DBSCAN,即Density-Based Spatial Clustering of Applications with Noise,基于密度的噪聲應(yīng)用空間聚類,本文將詳細(xì)介紹DBSCAN算法的原理及其Python實(shí)現(xiàn),需要的可以參考下2023-12-12
讓Python程序定時(shí)執(zhí)行的8種方法整理
在日常工作中,我們常常會用到需要周期性執(zhí)行的任務(wù),一種方式是采用?Linux?系統(tǒng)自帶的?crond?結(jié)合命令行實(shí)現(xiàn),另外一種方式是直接使用Python。本文整理了一下?Python?定時(shí)任務(wù)的實(shí)現(xiàn)方式,希望對大家有所幫助2023-01-01

