I am trying to copy the values of table cells on a web page to excel. The table has a variable number of rows, but I only need the first two columns.
Currently, I am using the following code, but it is taking a LONG time, a second or two for each row, which can take a long time for a big table.
Is there a faster way to do this that will copy over only the first two columns?
Currently, I am using the following code, but it is taking a LONG time, a second or two for each row, which can take a long time for a big table.
Is there a faster way to do this that will copy over only the first two columns?
VBA Code:
Dim Driver As New Selenium.ChromeDriver
Set Driver = CreateObject("Selenium.ChromeDriver")
Driver.Timeouts.ImplicitWait = 1
Driver.Start baseUrl:="https://website.com"
Driver.get "/table"
Dim Table As Selenium.WebElement
Set Table = Driver.FindElementById("tableID")
Dim AllRows As Selenium.WebElements
Dim SingleRow As Selenium.WebElement
Dim AllRowCells As Selenium.WebElements
Dim SingleCell As Selenium.WebElement
Dim OutputSheet As Worksheet
Dim RowNum As Long, ColNum As Long
Dim TargetCell As Range
Set OutputSheet = ThisWorkbook.Worksheets("REFERENCE")
Set AllRows = Table.findelementsbytag("tr")
For Each SingleRow In AllRows
RowNum = RowNum + 1
Set AllRowCells = SingleRow.findelementsbytag("td")
If AllRowCells.Count = 0 Then
Set AllRowCells = SingleRow.findelementsbytag("th")
End If
For Each SingleCell In AllRowCells
ColNum = ColNum + 1
Set TargetCell = OutputSheet.Cells(RowNum, ColNum)
TargetCell.Value = SingleCell.Text
Next SingleCell
ColNum = 0
Next SingleRow
Last edited: