从 http://assets URL 读取和保存图像
Reading and saving images from http://assets URLs
我正在尝试从不同的 URL 下载一堆图像并将它们本地保存在我的 PC 上。使用下面的前两个链接,我收到错误:HTTPError: Forbidden
并且我不知道为什么。会不会是因为网站对此有保护?
这是我使用的脚本:
import urllib.request
imgURL = "one of the links below"
urllib.request.urlretrieve(imgURL, "C:/Users/temp/pic1.jpg")
以下网址。前两个报错,最后一个不报错
就像你说的那样,它必须防止来自网站的机器人程序,解决方案是指定一个已知的用户代理
import urllib.request
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
imgURL = "one of your links"
urllib.request.urlretrieve(imgURL, "C:/Users/temp/pic1.jpg")
我正在尝试从不同的 URL 下载一堆图像并将它们本地保存在我的 PC 上。使用下面的前两个链接,我收到错误:HTTPError: Forbidden
并且我不知道为什么。会不会是因为网站对此有保护?
这是我使用的脚本:
import urllib.request
imgURL = "one of the links below"
urllib.request.urlretrieve(imgURL, "C:/Users/temp/pic1.jpg")
以下网址。前两个报错,最后一个不报错
就像你说的那样,它必须防止来自网站的机器人程序,解决方案是指定一个已知的用户代理
import urllib.request
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
imgURL = "one of your links"
urllib.request.urlretrieve(imgURL, "C:/Users/temp/pic1.jpg")