pythonurlliburlretrieve

How to download this image with Python?


I have a direct link like this: https://picjumbo.com/download/?d=cow.jpg&n=cow&id=1. But I cannot download it using urllib.request.urlretrieve() because when I access this url, the browser will download it automatically.


Solution

  • You can do the following:

    >>> import requests
    >>> content = requests.get('https://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&d=cow.jpg&n=cow').content
    >>> with open('downloaded_img.jpg', 'wb') as img:
    ...     img.write(content)
    ... 
    8153739
    >>>