我試圖從互聯網上使用python下載文件。 我已經tryed這些代碼:如何使用python下載隱藏/提供給html頁面的文件?
import urllib.requests
URL = 'http://www.mediafire.com/download/raju14e8aq6azbo/Getting+Started+with+MediaFire.pdf'
filename = "file.pdf"
urllib.request.urlretrieve(URL,filename)
和:
from urllib.request import urlopen
from shutil import copyfileobj
URL = 'http://www.mediafire.com/download/raju14e8aq6azbo/Getting+Started+with+MediaFire.pdf'
filename = "file.pdf"
with urlopen(URL) as in_stream, open(filename, 'wb') as out_file:
copyfileobj(in_stream, out_file)
(我發現這個最後的代碼爲:What command to use instead of urllib.request.urlretrieve?)
的問題是,這些代碼下載一個HTML文件,而不是我需要的名爲「MediaFire.pdf入門」的.pdf文件! 我正在尋找一種方式來下載隱藏/提供HTML頁面後面的文件。
有什麼建議嗎?
[this](http://www.blog.pythonlibrary.org/2012/06/07/python-101-how-to-download-a-file/)可能有幫助 –
有點奇怪,你的網址以.pdf結尾,並且您使用文件名也與file.pdf –
請定義損壞!它是空的?它是否包含一些其他信息?用十六進制或文本編輯器查看內容可能是一個好主意,看看它裏面可能有一個HTML錯誤頁面。 –