|
本帖最后由 MR_PP 于 2024-8-13 16:05 编辑
- <div class="blockcode"><blockquote>Sub DownloadImages()
- Dim url As String
- Dim folderPath As String
- url = "https://www.pep.com.cn/ebook/2022yjkcbz/yw/files/thumb/"
- ' 创建文件夹路径
- folderPath = ThisWorkbook.Path & "\images"
- If Dir(folderPath, vbDirectory) = "" Then
- MkDir folderPath
- End If
- For k = 1 To 109
- DownloadFile url & k & ".jpg", folderPath & "\image" & k & ".jpg"
- Next
- MsgBox "下载OK,文件放在:" & folderPath
- End Sub
- Sub DownloadFile(ByVal url As String, ByVal savePath As String)
- Dim http As Object
- Set http = CreateObject("MSXML2.XMLHTTP")
- http.Open "GET", url, False
- http.send
- If http.Status = 200 Then
- Dim stream As Object
- Set stream = CreateObject("ADODB.Stream")
- stream.Type = 1 ' adTypeBinary
- stream.Open
- stream.Write http.responseBody
- stream.SaveToFile savePath, 2 ' adSaveCreateOverWrite
- stream.Close
- End If
- End Sub
复制代码
|
|