Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget with python time limit

Tags:

python

wget

I have a large text file of URLs which I have to download via wget. I have written a small python script which basically loops through each domain name and download them using wget (os.system("wget "+URL)). But the problem is that wget just hangs on a connection if the remote server doesn't reply after connecting. How do I set a time limit in such a case? I want to terminate wget after some time if the remote server is not replying after connection.

Regards,

like image 638
Naruto Uzumaki Avatar asked Jul 07 '26 03:07

Naruto Uzumaki


1 Answers

Use the --timeout seconds argument to limit the time for a request. You can be more specific and use --connect-timeout seconds if needed. See the wget Manual for more information.

like image 81
akton Avatar answered Jul 08 '26 19:07

akton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!