这是我用来下载任何图片的代码(除了这个网站,它总是很好的工作www.pexels.com) . 它实际上下载了图片,但到了这个网站就被破坏了?我想知道为什么??在
url = "https://images.pexels.com/photos/844297/pexels-photo-844297.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
response = requests.get(url , stream = True)
file= open("Hello.jpg" , 'wb')
for chunk in response.iter_content(10000):
file.write(chunk)
file.close()
您需要在请求头中添加
user-agent
。在以下代码有效:
相关问题 更多 >
编程相关推荐