ferocious12
Member
Hi All - I am using the following code to scrap product titles from this website for page 1 & 2. It does the job for page 1 and list all the product titles in column A for page 1 but loop doesn't work for page 2. Will appreciate the help?
Code:
Sub DaraNext()
Dim ie As SHDocVw.InternetExplorer
Dim idoc As MSHTML.HTMLDocument
Dim doc_ele As MSHTML.IHTMLElement
Dim doc_eles As MSHTML.IHTMLElementCollection
Dim rownum As Variant
Dim Prodtitle As String
Set ie = New SHDocVw.InternetExplorer
ie.Visible = True
ie.navigate "https://www.daraz.lk/catalog/?from=input&q=sarees"
Do While ie.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "Loading"
Loop
Set idoc = ie.document
For k = 1 To 2
On Error Resume Next
For Each doc_ele In doc_eles
If doc_ele.className = ("ant-pagination-item-link") Then
doc_ele.Click
End If
Next doc_ele
Application.Wait Now + TimeValue("00:00:10")
' product title
Set doc_eles = idoc.getElementsByClassName("c16H9d")
rownum = 1
For Each doc_ele In doc_eles
If doc_ele.className = "c16H9d" Then
Prodtitle = doc_ele.innerText
ActiveSheet.Cells(rownum, 1).Value = Prodtitle
rownum = rownum + 1
End If
Next doc_ele
Next k
End Sub