简体   繁体   中英

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/

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").

Attempt 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

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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