是一种常见的自动化任务,可以通过编写脚本来实现。以下是一个完善且全面的答案:
Sub DownloadImagesFromURLs()
Dim URLs As Variant
URLs = Array("https://example.com/image1.jpg", "https://example.com/image2.jpg")
Dim i As Integer
For i = LBound(URLs) To UBound(URLs)
Dim url As String
url = URLs(i)
Dim http As Object
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", url, False
http.send
Dim response As String
response = http.responseBody
Dim fileName As String
fileName = "image" & i & ".jpg"
Dim fileStream As Object
Set fileStream = CreateObject("ADODB.Stream")
fileStream.Type = 1
fileStream.Open
fileStream.Write response
fileStream.SaveToFile fileName, 2
fileStream.Close
Set fileStream = Nothing
Set http = Nothing
Next i
End Sub
import requests
def download_images_from_urls(urls):
for i, url in enumerate(urls):
response = requests.get(url)
if response.status_code == 200:
file_name = f"image{i}.jpg"
with open(file_name, "wb") as file:
file.write(response.content)
urls = ["https://example.com/image1.jpg", "https://example.com/image2.jpg"]
download_images_from_urls(urls)
以上是使用VBA或Python从URL列表下载图像的完善且全面的答案。
领取专属 10元无门槛券
手把手带您无忧上云