实现简单的图片爬取(以Bing图片为例)
1.首先是分析网站
image.png2.得到图片的url为
https://tse2-mm.cn.bing.net/th/id/OIP.DoT44umkVWHF61SSbCk5YQHaJW?pid=Api&rs=1
3.在python中实现
#实现简单的图片爬取
import requests #导入requests库
if __name__ == "__main__":
#指定图片的url
url = 'https://tse2-mm.cn.bing.net/th/id/OIP.DoT44umkVWHF61SSbCk5YQHaJW?pid=Api&rs=1'
header = {
‘user-agent’ : ‘..........’
}
#发送请求,并获取图片数据
img_data = requests.get(url = url,headers = header).content
#存储数据,将数据保存为jpg
with open("./image.jpg",'wb') as fp:
fp.write(img_data)
网友评论