1

資格のある/使用可能なリンクを作成するために、特定のWebサイトcontact内の任意またはcontact usリンクを検索するスクリプトをvbaで作成しようとしています。私の現在のスクリプトは連絡先リンクを解析しますが、ほとんどの場合、後で再利用する資格がありません。つまり、壊れたものです。

私はこれまでに試しました:

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

壊れたリンクを適切なリンクに変えるにはどうすればよいですか?

4

1 に答える 1