9518423044
New Member
- Joined
- Aug 13, 2024
- Messages
- 3
- Office Version
- 2021
- Platform
- Windows
VBA Code:
Sub ScrapeAmazonPrices()
Dim ie As Object
Dim html As Object
Dim urls As Range
Dim cell As Range
Dim price As String
' Initialize Internet Explorer
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
' Set the range of URLs
Set urls = ThisWorkbook.Sheets("Sheet1").Range("A1:A" & ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
' Loop through each URL
For Each cell In urls
If cell.Value <> "" Then
' Navigate to the URL
ie.navigate cell.Value
Do While ie.Busy Or ie.readyState <> 4: DoEvents: Loop
' Get the HTML document
Set html = ie.document
' Extract the price
On Error Resume Next
price = html.getElementsByClassName("a-price-whole")(0).innerText
On Error GoTo 0
' Write the price in the next column
cell.Offset(0, 1).Value = price
End If
Next cell
' Quit Internet Explorer
ie.Quit
Set ie = Nothing
Set html = Nothing
MsgBox "Scraping Completed!"
End Sub
Last edited by a moderator: