利用Python中的requests库爬取视频的图片
一、总结
一句话总结:
可以用requests的get方法获取图片响应数据,因为是二进制,所以用response的content属性获取图片二进制数据,然后用python文件操作把图片存下来就可以了
importrequests
headers={"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
}
url="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1594286367651&di=7f176da3578634bc67e5f38e24438b0c&imgtype=0&src=http%3A%2F%2Fbpic.588ku.com%2Felement_origin_min_pic%2F16%2F07%2F10%2F205782447d16b2a.jpg%2521%2Ffwfh%2F804x804%2Fquality%2F90%2Funsharp%2Ftrue%2Fcompress%2Ftrue"response= requests.get(url,headers=headers)print(response.status_code)#print(response.text)#print(response.content)
with open("test.jpg","wb") as f:
f.write(response.co