[RESOLVED] (Another) Get Table with WebBrowser
I built a simple webbrowser program, and now I want to download a specific table (League stats) on a specific website (http://www.nfl.com/standings?category=league). I can save the entire page and then using copy-paste, put it into an Excel spreadsheet...however, I would like to avoid those manual steps. I have looked at several postings on how to get table data, but have failed in all attempts to make any of them work. Here is a pic of my webbrowser on the page which includes the table I want...(at the bottom of the snapshot). Can anyone assist? Thanks in advance.
Attachment 93231
Re: (Another) Get Table with WebBrowser
this will paste into a single column, should be easy enough to split it into multiple, but out of time now
Code:
For Each ele In wb.document.all 'getelementsbytagname("Table")
If ele.innertext = "Conf" Then
clipboard.Clear
clipboard.SetText ele.offsetparent.offsetparent.innertext
Exit For
End If
Range("a1").PasteSpecial
where wb is an instance of IE or a shell window
Re: (Another) Get Table with WebBrowser
What I have tried is to get a string of the entire 'text' of the html file with this code:
Code:
dim myText as string
myText = frmMain.WebBrowser1.Document.documentElement.innerHTML
It APPEARS that the entire file is not dumped into my string variable as when I search the text, I do not find any <table> tags
I thought it might be that the page is in frames, so I tried this:
Code:
Dim i As Integer
For i = 0 To frmMain.WebBrowser1.Document.frames.length - 1
myText = myText & WebBrowser1.Document.frames(i).Document.documentElement.innerHTML
Next i
but I got this error: "Runtime Error Access is Denied." So I assumed there are no frames on the page.
I CAN get the entire page dumped to a .html web page and then can open it with Word and see the table, or with Notepad and see the <table> tags. So this led me to believe my initial dump into myText did not get everything.
I do that with this command: WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT
I guess I could use Shell to open the file I saved (html format) and then put that file into a string and THEN extract the data after the appropriate <table> tag....but that would be cumbersome, and a lot of extra coding to put that data into an excel spreadsheet and/or Access DB table.
Re: (Another) Get Table with WebBrowser
Thx Westconn....JUST saw your post...I will try later...thanks....
Re: (Another) Get Table with WebBrowser
Not sure how regular you want to do this but I simply used "inspect element" in Chrome copied the table as HTML (from the Elements tab) and pasted into excel. It pasted column by column and row by row.
Just thought I would mention this. Apologies if it is off track.
Re: (Another) Get Table with WebBrowser
i just edited the code i posted as when rushing out this morning i left in a couple of things that should have been removed, that was because i wrote and tested in VBA where there is no clipboard object
for whatever reason the table you want does not appear to be in a table element
Re: (Another) Get Table with WebBrowser
bazz.....thanks...I'll try that at home (can't load Chrome on work comp)....It's a weekly thing during the NFL season...so if that works, that will suffice. HOWEVER, am still working on the VB webbrowser approach...who knows, I may eventually figure that one out.
If Westconn1 can't figure out why that 'table' doesn't appear as a table element (post #6), who am I???? :-)
Re: (Another) Get Table with WebBrowser
I am sure Westconn1 will get there. I am sure any browser that offers debugging addons will do. Most of the major browsers will do I am sure. I mainly use Chrome.
Re: (Another) Get Table with WebBrowser
try like
Code:
tabel = ""
For Each ele In wb.document.all
If ele.innertext = "Conf" Then
Set tms = ele.offsetparent.offsetparent.getelementsbytagname("tr")
For rw = 0 To tms.Length - 1
Set mytm = tms(rw).getelementsbytagname("td")
For col = 0 To mytm.Length - 1
tabel = tabel & " " & mytm(col).innertext & vbTab
Next
tabel = tabel & vbNewLine
Next
clipboard.Clear
clipboard.SetText CStr(tabel)
Exit For
End If
Next
Range("a1").PasteSpecial
appears to give the desired result
Re: (Another) Get Table with WebBrowser
HUAH!!! I will ....thanks.....
Re: (Another) Get Table with WebBrowser
Westconn (Pete?)....fantastic! DOES work like a charm....thanks.