import requests
import time
BING_IMG = 'https://cn.bing.com/th?id=OHR.ReindeerNorway_ZH-CN5913190372_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp'
DEFAULT_IMG_NAME = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + '.jpg'
def get_image(url):
"""
:param url: image link address
:return: binary image data
"""
response = requests.get(url)
img_b = response.content
return img_b
def save_image(img_b, file_name):
"""
:param file_name: image file name
:param img_b: binary image data
:return: None
"""
with open(file_name, 'wb') as f:
f.write(img_b)
def download_image(utl=BING_IMG, file_name=DEFAULT_IMG_NAME):
"""
:param utl: image link address
:param file_name: image file name
:return: None
"""
img_b = get_image(utl)
save_image(img_b, file_name)
if __name__ == '__main__':
download_image()
Python下载Bing首页图片
最新推荐文章于 2021-06-13 14:31:40 发布