我正在尝试在 vba 中创建一个脚本,该脚本将在任何给定网站contact
中查找任何链接或contact us
链接,以便提供合格的/可用链接。我当前的脚本确实解析了联系链接,但大多数时候它们没有资格在以后重用,这意味着损坏的链接。
到目前为止我已经尝试过:
Sub FetchCustomizedLink()
Dim Http As New XMLHTTP60, Html As New HTMLDocument
Dim link As Variant, links As Variant, targetlink$
links = Array( _
"http://www.innovaprint.com.sg/", _
"https://www.plexure.com.sg/", _
"http://www.mount-zion.biz/", _
"https://stackoverflow.com/" _
)
For Each link In links
targetlink = None
With Http
.Open "GET", link, False
.setRequestHeader "User-Agent", "Mozilla/5.0"
On Error Resume Next
.send
On Error GoTo 0
Html.body.innerHTML = .responseText
End With
With Html.querySelectorAll("a[href]")
For I = 0 To .Length - 1
If InStr(1, .item(I).innerText, "contact", 1) > 0 Then
targetlink = .item(I).getAttribute("href")
Exit For
End If
Next I
End With
Debug.Print targetlink
Next link
End Sub
我得到的输出:
about:/contact.html
https://www.plexure.com.sg/contact
about:contactus.html
https://stackoverflow.com/company/contact
我希望得到的输出:
http://www.innovaprint.com.sg/contact.html
https://www.plexure.com.sg/contact
http://www.mount-zion.biz/contactus.html
https://stackoverflow.com/company/contact
如何将损坏的链接变成合格的链接?