小编Vin*_*iuz的帖子

如何使用python下载html页面后面的文件?

我正在尝试使用python从互联网上下载文件.我试过这段代码:

import urllib.requests
URL = 'http://www.mediafire.com/download/raju14e8aq6azbo/Getting+Started+with+MediaFire.pdf'
filename = "file.pdf"
urllib.request.urlretrieve(URL,filename)
Run Code Online (Sandbox Code Playgroud)

和:

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)
Run Code Online (Sandbox Code Playgroud)

(我在最后的代码中找到了:使用什么命令代替urllib.request.urlretrieve?)

问题是这段代码下载了一个html文档而不是我需要的名为"MediaFire.pdf入门"的.pdf文件!我正在寻找一种方法来下载html页面后面提供的文件.

有什么建议吗?

python file download

0
推荐指数
1
解决办法
1670
查看次数

标签 统计

download ×1

file ×1

python ×1