I want to scrape a table from chrome in excel vba with selenium, but there are several (currently 2) thead and tbody elements in the class. The code I’m currently using only takes the data from the first thead and tbody . I managed to solve it with Internet Explorer, but it doesn’t work with Selenium. Unfortunately, ie is a bit out of date…
the current piece of the page’s source code in the image[text]()
Sub test2()
Dim driver As New WebDriver
Dim rowc, cc, columnC As Integer
rowc = 2
driver.Start "chrome"
driver.Get "https://www.betexplorer.com/football/argentina/primera-nacional/"
For Each th In driver.FindElementByClass("stats-table-container").FindElementByTag("thead").FindElementsByTag("tr")
cc = 1
For Each t In th.FindElementsByTag("th")
Munka1.Cells(22, cc).Value = t.Text
cc = cc + 1
Next t
Next th
For Each tr In driver.FindElementsByClass("stats-table-container").FindElementsByTag("tbody").FindElementsByTag("tr")
columnC = 1
For Each td In tr.FindElementsByTag("td")
Munka1.Cells(rowc, columnC).Value = td.Text
columnC = columnC + 1
Next td
rowc = rowc + 1
Next tr
'Application.Wait Now + TimeValue("00:00:20")
End Sub
I tried this as well, but it always throws an error
For Each th In driver.FindElementByClass("stats-table-container").FindElementByTag("thead")(1).FindElementsByTag("tr")
If anyone could help, I would greatly appreciate it!
Karesz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.