2种方法实现python从网站下载图片

it2023-09-28  90

1、使用requests 使用requests模块的get方法获取URL,并将结果存储到一个名为“myfile”的变量中。然后,将这个变量的内容写入文件。

import requests html = "http://inews.gtimg.com/newsapp_ls/0/12640396123_640330/0.png" myfile = requests.get(html) open("D:/3.png","wb").write(myfile.content)

2、使用wget

在这段代码中,URL和路径(图像将存储在其中)被传递给wget模块的download方法。

import wget html = "http://inews.gtimg.com/newsapp_ls/0/12640396123_640330/0.png" wget.download(html,"D:/3.png")
最新回复(0)