I am using VBA to scrape data from an html document. The document has an iframe within it. I can use the web browser's "inspect element" an see the text; however, I cannot get to it with VBA. Here is the code, I am using, it has worked well with other elements.
Sub NewMain()
Dim i As Integer
Dim IE As InternetExplorer
Dim sc As MSHTML.IHTMLElementCollection
Dim scObj As MSHTML.IHTMLGenericElement
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
Debug.Print "ie count " & IE_count
For x = 0 To (IE_count - 1)
On Error Resume Next
my_URL = objShell.Windows(x).Document.Location
my_title = objShell.Windows(x).Document.title
If my_URL like "http://www.loopnet.com/xNet/Mainsite/Report/Report.aspx?" & "*" Then
Debug.Print "You have the document"
Set IE = objShell.Windows(x)
Set mydoc = IE.Document
Set sc = mydoc.getElementsByTagName("script")
For Each scObj In sc
Debug.Print scObj.innerText
Next
End If
Next
End Sub
The html that I am trying to read is below. I am trying to get the data in a script tag that is inside the body element; although, I am also thinking the I can just access the html class="dj_ie je_ie10 dj_contentbox" id="ln" item. However, I am at a loss on how to do it. Any help would be greatly appreciated.
<iframe name="reportFrame" width="1100" height="1100" class="report-
frame" id="reportFrame" src="http://reporting.loopnet.com"
frameborder="0" scrolling="no" style="height: 2530px;"></iframe>
<!DOCTYPE html>
<html class="dj_ie dj_ie10 dj_contentbox" id="ln">
<head>...</head>
<body>...</body>
</html>
</iframe>
the primary website is open source. LoopNet.com they list real estate for sale and lease. looking at the site, you select properties interest, then, you click "create a report". This html snippet and what I am trying to scrape the data from is the "listing comparison report".