我创建了一个宏来解析网页中的某些链接及其相关文本。当我在fetchData()
中打印结果时,就可以全部得到。但是,当我在printResult()
中打印结果时,得到的结果很少。
如何在printResult()
中将所有结果打印到另一个子目录中?
Sub fetchData()
Const baseUrl = "https://www.psacard.com"
Const link = "https://www.psacard.com/psasetregistry/baseball/company-sets/16"
Dim Http As New XMLHTTP60, Html As New HTMLDocument
Dim post As Object, nUrl$, sName$
With Http
.Open "GET", link, False
.send
Html.body.innerHTML = .responseText
End With
For Each posts In Html.getElementsByTagName("td")
If posts.getElementsByTagName("a").Length Then
nUrl = baseUrl & Split(posts.getElementsByTagName("a")(0).getAttribute("href"), "about:")(1)
sName = posts.getElementsByTagName("a")(0).innerText
printResult nUrl, sName
End If
Next posts
End Sub
Sub printResult(ByVal nUrl As String, ByVal sName As String)
Debug.Print nUrl, sName
End Sub