I am trying to scrap product titles and prices from the website to copy in column A&B of sheet(1). The code was originally developed for Amazon. Any help to update it to get it. The result will be like image below. Thank you !
Code
- Public Sub Dara_Product()
- 'VBE>Tools>References> Microsoft HTML Object Library
- Dim html As MSHTML.HTMLDocument
- Set html = New MSHTML.HTMLDocument
- With CreateObject("MSXML2.XMLHTTP")
- ' change the url for the page of amazon from where to copy data
- .Open "GET", "https://www.daraz.lk/catalog/?from=input&q=sarees&ppath=31186:3287", False .setRequestHeader "User-Agent", "Mozilla/5.0" .send html.body.innerHTML = .responseText
- End With
- ' 1. declare additional headers as variable
- Dim headers(), titles As Object, prices As Object, original_prices As Object
- Dim seller As Object
- headers = Array("Title", "Price")
- With html Set titles = .querySelectorAll(".c3gUW0,.c13VH6") Set prices = .querySelectorAll(".------------") End With
- Dim results(), r As Long, priceInfo As String
- ReDim results(1 To titles.Length, 1 To UBound(headers) + 1)
- For r = 0 To titles.Length - 1 results(r + 1, 1) = titles.Item(r).innerText
- Next
- Dim ws As Worksheet
- Set ws = ThisWorkbook.Worksheets("Sheet1")
- With ws .Cells(1, 1).Resize(1, UBound(headers) + 1) = headers .Cells(2, 1).Resize(UBound(results, 1), UBound(results, 2)) = results
- End With
- End sub