我試圖使用urllib.urlretrieve從服務器獲取一些文件。我需要它忽略系統上的任何代理設置。我看了一下urllib.urlopen,但我不知道如何使用它來下載文件。使用urllib.urlretrieve並忽略代理
目前我的電話看起來是這樣的:
urllib.urlretrieve(url, import_path + "/%s" % filename)
任何援助將是巨大的。謝謝。
我試圖使用urllib.urlretrieve從服務器獲取一些文件。我需要它忽略系統上的任何代理設置。我看了一下urllib.urlopen,但我不知道如何使用它來下載文件。使用urllib.urlretrieve並忽略代理
目前我的電話看起來是這樣的:
urllib.urlretrieve(url, import_path + "/%s" % filename)
任何援助將是巨大的。謝謝。
在Python文檔中,據說filehandle = urllib.urlopen(some_url, proxies={})
將導致系統不向我們提供任何代理,甚至是系統的代理。
處理urlopen()
非常簡單。 filehandle
支持read()
獲取數據的方法。然後打開一個文件並將數據寫入它。
讓filehandle
成功通話後充滿數據。
fi=open(some_file,mode)
fi.write(filehandle.read())
fi.close()
只是想我會發佈一個完整的例子。
#!/bin/python
import urllib
filehandle = urllib.urlopen("https://docs.python.org/2/library/urllib.html", proxies={})
fi=open("read_this.html", "w")
fi.write(filehandle.read())
fi.close()