(Solved) – Get email from HTML get XMLHTTP faster

(solved)-–-get-email-from-html-get-xmlhttp-faster

I have created a user-defined function for the purpose of getting an email from specific html like that

Sub Test()
Debug.Print GetEmailFromHTML("https://www.archaeology.lk/pharmacylocator/pharmacy_details.php?PhamercyID=589")
End Sub

Function GetEmailFromHTML(sURL As String)
Dim html As New HTMLDocument

With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", sURL, False
    .send
    html.body.innerHTML = .responseText
End With

On Error Resume Next
    GetEmailFromHTML = html.querySelectorAll("a[href*='mailto']")(0).innerText
On Error GoTo 0
Set html = Nothing
End Function

When running the Test macro, the code takes too much time but it works well at last. Is there a way to get XMLHTTP works faster or is there alternative approach to do so? All that I need from the URL is to get the email information.

Leave a Reply

Your email address will not be published. Required fields are marked *