xyobi
asked on
Extract the Page Source of URL as a String using VBA
Hi,
I am trying to extract the HTML Page Source of a given URL as a String. I found the code below which works but for some reason doesn't work all the time (it gives various different errors sporadically).
I am trying to extract the HTML Page Source of a given URL as a String. I found the code below which works but for some reason doesn't work all the time (it gives various different errors sporadically).
Public Function gsGetPageSource(URLToCrawl As String) As String
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Navigate URLToCrawl
Do While .Busy And Not .ReadyState = 4
DoEvents
Loop
gsGetPageSource = IIf(StrComp(.Document.Title, "Cannot find server", vbTextCompare) = 0, vbNullString, .Document.Body.outerHTML)
.Quit
End With
Set ie = Nothing
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thydzik... you are a legend, thanks so much for your help
nicobo... thanks for your solution, I tried it out and it looked interesting but im not sure if it does exactly as i want as i dont have the skills required to make the necessary changes
nicobo... thanks for your solution, I tried it out and it looked interesting but im not sure if it does exactly as i want as i dont have the skills required to make the necessary changes
ASKER
thanks
https://www.experts-exchange.com/questions/26977101/Get-External-Web-Result-into-Excel.html
You'll need the function GetInternetResult in the Postalcode module of the attached file. You can call this function for example like this:
?GetInternetResult("https://www.experts-exchange.com","Sof