Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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).

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

Open in new window

0
xyobi
Asked:
xyobi
  • 2
1 Solution
 
Nico BontenbalCommented:
See comment 35465535 in this question:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26977101.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("www.experts-exchange.com","Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26977101.html","")

0
 
thydzikCommented:
try the attached;
Sub tester()

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objHTTP = CreateObject("Msxml2.XMLHTTP")
 
    objHTTP.Open "GET", "http://google.com", False
    objHTTP.send
    strPageText = objHTTP.responseText
    MsgBox strPageText
End Sub

Open in new window



grab-html.xls
0
 
xyobiAuthor Commented:
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
0
 
xyobiAuthor Commented:
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now