Sluggun
05-14-2021, 12:11 PM
I am scraping price data from websites and although I can get the exact output I am looking for in the "Immediate" window, when I try to send it to a worksheet, it overwrites the cells with earlier data output with the last output.
Please help!!
Option Explicit
Private cd As Selenium.ChromeDriver
Sub WeeklyPrices()
' Open Chrome
Dim cd As Selenium.ChromeDriver
Dim RowNum As Integer, ColNum As Integer
Set cd = New Selenium.ChromeDriver
Dim Count As Integer
For Count = 1 To 2
Dim Value As String
Dim names As Range
Set names = Range("c1:c2")
Dim cell As Range
For Each cell In names
cd.AddArgument "--headless"
cd.start
cd.get cell.Value
'Find Headers
Dim H2Headers As Selenium.WebElements
Dim H2Header As Selenium.WebElement
Set H2Headers = cd.FindElementsByCss("h2:nth-of-type(4)")
For Each H2Header In H2Headers
'Debug.Print H2Header.Text
RowNum = Count
ColNum = 1
Cells(RowNum, ColNum) = H2Header.Text
Next H2Header
' Find Prices
Dim OtdListItems As Selenium.WebElements
Dim OtdListItem As Selenium.WebElement
Set OtdListItems = cd.FindElementsByCss("ul:nth-of-type(4)")
For Each OtdListItem In OtdListItems
'Debug.Print OtdListItem.Text
RowNum = Count
ColNum = 2
Cells(RowNum, ColNum) = OtdListItem.Text
Next OtdListItem
Next cell
Next Count
cd.Quit
End Sub
Please help!!
Option Explicit
Private cd As Selenium.ChromeDriver
Sub WeeklyPrices()
' Open Chrome
Dim cd As Selenium.ChromeDriver
Dim RowNum As Integer, ColNum As Integer
Set cd = New Selenium.ChromeDriver
Dim Count As Integer
For Count = 1 To 2
Dim Value As String
Dim names As Range
Set names = Range("c1:c2")
Dim cell As Range
For Each cell In names
cd.AddArgument "--headless"
cd.start
cd.get cell.Value
'Find Headers
Dim H2Headers As Selenium.WebElements
Dim H2Header As Selenium.WebElement
Set H2Headers = cd.FindElementsByCss("h2:nth-of-type(4)")
For Each H2Header In H2Headers
'Debug.Print H2Header.Text
RowNum = Count
ColNum = 1
Cells(RowNum, ColNum) = H2Header.Text
Next H2Header
' Find Prices
Dim OtdListItems As Selenium.WebElements
Dim OtdListItem As Selenium.WebElement
Set OtdListItems = cd.FindElementsByCss("ul:nth-of-type(4)")
For Each OtdListItem In OtdListItems
'Debug.Print OtdListItem.Text
RowNum = Count
ColNum = 2
Cells(RowNum, ColNum) = OtdListItem.Text
Next OtdListItem
Next cell
Next Count
cd.Quit
End Sub