简体   繁体   English

使用 python 从 URL 下载文件

[英]Download files from URLs with python

I am trying to download files using URLs eg https://filehippo.com/download_vlc-media-player-64/post_download/我正在尝试使用 URL 下载文件,例如https://filehippo.com/download_vlc-media-player-64/post_download/

I used multiple methods to download them found online, but I do not see output (cannot see the download files or cannot even print them to see something happening just "Process finished with exit code 0").我使用了多种方法来下载在线找到的它们,但我没有看到输出(无法看到下载文件,甚至无法打印它们以查看正在发生的事情,只是“进程已完成,退出代码为 0”)。

Attempt 1尝试 1

import urllib2
response = urllib2.urlopen('http://www.example.com/file_to_download')
html = response .read()
print(html) --> output is blank

Attempt 2 https://www.tutorialspoint.com/downloading-files-from-web-using-python尝试 2 https://www.tutorialspoint.com/downloading-files-from-web-using-python

I am not sure what I am missing here, any help is apricated.我不确定我在这里遗漏了什么,任何帮助都会得到帮助。

import urllib2

filedata = urllib2.urlopen('http://www.example.com/file_to_download')
datatowrite = filedata.read()

with open('/Users/location.jpg', 'wb') as f:
f.write(datatowrite)

or要么

import wget

print('Beginning file download with wget module')

url = 'http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg'
wget.download(url, '/Users/loca.jpg')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM