Hi,
I'm trying to grab an html table through vba: http://www.numberfire.com/nfl/fantas...l-projections/
The table is set up as 14 columns of static html data (player, position, passing yds, etc), and then 3 more columns of data that load based on a list box selection (FanDuel, DraftKings, etc)
I'd like to generate an excel file that has all the static data, and then all the available additional data. The table html has all the information I want (static data plus stats according to FanDuel, DraftKings, etc) but my code is not picking up this additional data. The code I have right now goes to the website, loops through all the <tr> tags in the relevant table's html, and prints it out.
Here's my code:
Sub scrapeAllStats()
Dim ie As Object
Dim tbls, tbl, trs, tr, tds, td, r, c
Sheets("allStatsTest").Select
Set ie = CreateObject("internetexplorer.application")
ie.Navigate "http://www.numberfire.com/nfl/fantasy/fantasy-football-projections/draftkings"
Application.Wait Now + TimeSerial(0, 0, 4)
'wait for page to load
Set tbls = ie.Document.getElementsByTagName("table")
For r = 0 To tbls.Length - 1
Debug.Print r, tbls(r).Rows.Length
Next r
'count the rows in the table
Set tbl = ie.Document.getElementsByTagName("table")(0)
Set trs = tbl.getElementsByTagName("tr")
For r = 1 To trs.Length - 1
Set tds = trs(r).getElementsByTagName("td")
'if no <td> then look for <th>
If tds.Length = 0 Then Set tds = trs(r).getElementsByTagName("th")
For x = 0 To 15
ActiveSheet.Range("A1").Offset(r, x).Value = tds(x).innerText
Next x
'loop through all the <tr> elements that I care about
Next r
ie.Quit
End Sub
And here is the html in question:
img1.PNG
It gets all the data above the red line, but doesn't get anything below, not even the table's default values. My first thought was that that data loaded slower than the rest, so I tried making the code wait 20 seconds before proceeding, but that didn't do anything. My current guess are that even though the html data has the same "tr" tag, it's in some kind of different class. (I've never dealt with html, so I'm sure I could be missing something) Not gonna lie, I'm pretty lost here
Any advice would be greatly appreciated. Thank for reading!
Bookmarks