'wget fails to perform in a for loop
I want to iterate through a list of url's (linking to pictures) and perform a wget to download those pictures.
But the url's are between quotation marks.
I initially put a $ sign in front of the picture variables. It works in a colab notebook, I can actually download the pictures this way in my notebook, but it does not work when I launch the script via my Windows command.
for follower in tweepy.Cursor(api.get_followers, screen_name='@'+screen_name, wait_on_rate_limit=True, count=200).items(9000):
followers_profile_pic.append(follower.profile_image_url_https)
for pic in followers_profile_pic:
pic_id = re.search(pattern, pic).group(1)
big_pic = f"https://pbs.twimg.com/profile_images/{pic_id}_400x400.jpg"
quality_pic.append(big_pic)
for picture in quality_pic:
wget picture
Solution 1:[1]
can actually download the pictures this way in my notebook, but it does not work when I launch the script via my Windows command.
If portability is concern to you then it is wise to limit to standard library if feasible. There is function specially designed for downloading files - namely urllib.request.urlretrieve. Most basic usage is to provide URL and filename, for example:
import urllib.request
urllib.request.urlretrieve("https://www.example.com","index.html")
urllib.request is part of standard library so generally it should be sufficent to have python installed, unlike external modules, e.g. requests which need separate installation. If you want to know more about urllib.request.urlretrieve read linked docs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daweo |
