如何使用 Python 3 从 url 下载图像?

How do I download a image from a url with Python 3?

任何人都可以用下面的代码帮助我,我正在尝试使用 Python 从下面 url 下载图像。我在网上查看并获得了以下代码,但它在 urllib 请求中给了我以下错误?

import urllib.request 
from selenium import webdriver
driver = webdriver.Chrome('c://CSALE//chromedriver.exe')
driver.get('https://kbdevstorage1.blob.core.windows.net/asset-blobs/19950_en_1')
img = driver.find_element_by_xpath('/html/body/img').get_attribute('src')
urllib.request.urlretrieve(img, "wolf.png")
driver.close()

错误:

urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>

我用请求模块做了以下操作:

img = driver.find_element_by_xpath('/html/body/img').get_attribute('src')

data = requests.get(img).content
local_filename = 'Dog_with_Selenium.jpg'

with open(local_filename, 'wb') as f:
  f.write(data)