Search code examples
pythonseleniumurllib

How to choose where Urllib saves an image?


I am using selenium and urllib to download images, and as of now, urllib just saves into the folder where the python script is. Is there a way to change where the images are saved?

url2 = url.get_attribute("src")
urllib.request.urlretrieve(url2, abbr2 + ".jpg")

thank you!


Solution

  • You can include a directory path as part of the filename. You can supply an absolute path or a relative path. E.g., to save it in the parent folder, you would provide "../" + abbr2 + ".jpg"