Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using wget via Python [duplicate]

Tags:

python

linux

How would I download files (video) with Python using wget and save them locally? There will be a bunch of files, so how do I know that one file is downloaded so as to automatically start downloding another one?

Thanks.

like image 352
CoreIs Avatar asked Mar 18 '10 04:03

CoreIs


People also ask

How do I use wget in Python?

Run the wget command below and add the --directory-prefix option to specify the file path ( C:\Temp\Downloads ) to save the file you're downloading. Open File Explorer and navigate to the download location you specified (C:\Temp\Downloads) to confirm that you've successfully downloaded the file.

Does wget work in Python?

wget is a URL network downloader that can work in the background, and it helps in downloading files directly from the main server. In Python, this task is done by using the wget module.

What is import wget in Python?

One of the simplest way to download files in Python is via wget module, which doesn't require you to open the destination file. The download method of the wget module downloads files in just one line. The method accepts two parameters: the URL path of the file to download and local path where the file is to be stored.

Does wget overwrite?

If you specify the output file using the -O option it will overwrite any existing file. Run multiple times will keep over-writting index. html.


1 Answers

Short answer (simplified). To get one file

 import urllib.request  urllib.request.urlretrieve("http://google.com/index.html", filename="local/index.html") 

You can figure out how to loop that if necessary.

like image 125
Mark Lakata Avatar answered Oct 09 '22 16:10

Mark Lakata