Created
December 31, 2017 11:46
-
-
Save ganesh092929/aeb0b19e0342819a229d99157f82858a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ScrapeCarDataPt4() | |
Dim IE As InternetExplorer | |
Set IE = CreateObject("InternetExplorer.Application") | |
IE.Visible = True | |
IE.Navigate "https://carousell.com/categories/cars-32/cars-for-sale-1173/" | |
Do While IE.ReadyState <> READYSTATE_COMPLETE: Loop | |
Dim CarListings As IHTMLElementCollection | |
Dim CarListing As IHTMLElement | |
Dim ItemName As IHTMLElementCollection | |
Dim ItemDetails As IHTMLElementCollection | |
Dim ItemDetail As IHTMLElement | |
Dim wb As Workbook | |
Dim ws As Worksheet | |
Set wb = ThisWorkbook | |
Set ws = wb.Sheets("Sheet1") | |
Dim rowCnt, colmnCnt As Integer | |
rowCnt = 1 | |
Set CarListings = IE.Document.body.getElementsByClassName("col-lg-3 col-md-4 col-sm-4 col-xs-6") | |
For Each CarListing In CarListings | |
Set ItemName = CarListing.getElementsByClassName("r-k") | |
ws.Cells(rowCnt, 1).Value = ItemName(0).innerText | |
colmnCnt = 2 | |
Set ItemDetails = CarListing.getElementsByTagName("dd") | |
For Each ItemDetail In ItemDetails | |
ws.Cells(rowCnt, colmnCnt).Value = ItemDetail.innerText | |
colmnCnt = colmnCnt + 1 | |
Next ItemDetail | |
rowCnt = rowCnt + 1 | |
Next CarListing | |
IE.Quit | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment