python request+open 下载任意文件

实例源码

    link = 'https://www.google.com.au/url?sa=i&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwiaucyRvurcAhVaMt4KHbRMCOcQjRx6BAgBEAU&url=https%3A%2F%2Fimage.so.com%2F&psig=AOvVaw3u3MRzkFwBIJglN_Ir-Wy0&ust=1534265396809360'

    # 第一步:获取文件
    img_response = requests.get(link)

    # 第二步:设文件名
    filename = str(uuid.uuid4()) + '.jpg'

    # 第三步:保存文件
    with open(filename,'wb') as f:
        f.write(img_response.content)

你可能感兴趣的:(编程语言)