import requests
#发送网络请求
response = requests.get('https://www.baidu.com/img/bd_logo1.png?where=super')
print(response.content)#打印二进制数据
with open('百度logo.png', 'wb') as f:#通过open()函数将二进制数据写入本地文件
f.write(response.content)#写入

这段代码演示了如何使用requests库从指定URL下载图片,并将其保存到本地为'百度logo.png'。首先,发送GET请求获取图片二进制数据,然后使用with open()将数据写入文件。
import requests
#发送网络请求
response = requests.get('https://www.baidu.com/img/bd_logo1.png?where=super')
print(response.content)#打印二进制数据
with open('百度logo.png', 'wb') as f:#通过open()函数将二进制数据写入本地文件
f.write(response.content)#写入


被折叠的 条评论
为什么被折叠?