|
Sub GetImgUrls()
'工具——引用MicrosoftXML,v6.0
'工具——引用Microsoft HTML Object Library
Dim oDoc As HTMLDocument
Dim url As String
url = "https://tieba.baidu.com/p/1910382046"
Set oDoc = New HTMLDocument '加载目标页面
oDoc.body.innerHTML = GetHttp(url) '获取所有<img>标签
' For Each oImg In oDoc.getElementsByTagName("img")
' Debug.Print oImg.src
' Next
Dim link_ad$, fi_na$
For Each oImg In oDoc.getElementsByClassName("BDE_Image")
' Debug.Print oImg.src
link_ad = oImg.src
fd = Split(link_ad, ".")
后缀 = fd(UBound(fd))
n = n + 1
fi_na = ThisWorkbook.path & "/" & n & "." & 后缀
Call S_savefile(link_ad, fi_na)
Next
End Sub
Function GetHttp(sUrl As String) As String
Dim oXHTTP As Object
Set oXHTTP = CreateObject("MSXML2.XMLHTTP") '获取网页源代码
oXHTTP.Open "GET", sUrl, False
oXHTTP.send
GetHttp = oXHTTP.responseText
End Function
Sub S_savefile(sUrl As String, sfile_name1 As String)
Dim oXHTTP As Object
' Set oXHTTP = CreateObject("MSXML2.XMLHTTP") '获取网页源代码
Set oXHTTP = CreateObject("microsoft.xmlhttp")
oXHTTP.Open "GET", sUrl, False
oXHTTP.send
Dim rebo() As Byte
rebo = oXHTTP.responseBody
Open sfile_name1 For Binary As #1
Put #1, , rebo()
Close #1
End Sub
供参考:
|
评分
-
2
查看全部评分
-
|