I wrote this to scrape album review data from AOTY into a spreadsheet. Check it out and let me know what I could've done better.
Option Explicit
Const classAlbum As String = "listLargeTitle"
Const classScore As String = "listScoreContainer"
Const classRating As String = "listScoreValueContainer"
Const classReview As String = "listScoreText"
Const classNext As String = "pageSelect"
Sub ScrapeAOTY()
Dim IE As MSXML2.XMLHTTP60
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLBody As MSHTML.HTMLBody
Dim Albums As Object
Dim Ratings As Object
Dim Reviews As Object
Dim MetaData As Object
Dim InnerMeta As Object
Dim nextPage As Object
Dim selection As Object
Dim sheet As Worksheet
Dim aotyYear As String
Dim url As String
Dim bookmark As String
Dim album As String
Dim review As String
Dim releaseDate As String
Dim genre As String
Dim test As String
Dim rating As Double
Dim index As Long
Dim row As Long
Dim page As Long
Dim pageLoading As Boolean
Dim exitFlag As Boolean
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
aotyYear = InputBox("Input the year you're scraping")
If aotyYear < 1900 Then Exit Sub
url = "http://www.albumoftheyear.org/ratings/6-highest-rated/" & aotyYear & "/1"
Set sheet = ThisWorkbook.Worksheets("ScrapeSheet")
row = 2
exitFlag = False
page = 1
Do
Set IE = New MSXML2.XMLHTTP60
url = "http://www.albumoftheyear.org/ratings/6-highest-rated/" & aotyYear & "/" & page
IE.Open "GET", url, False
IE.send
Do While IE.ReadyState <> 4
DoEvents
Loop
Set HTMLDoc = New MSHTML.HTMLDocument
Set HTMLBody = HTMLDoc.body
HTMLBody.innerHTML = IE.responseText
Set Albums = HTMLDoc.getElementsByClassName(classAlbum)
Set Ratings = HTMLDoc.getElementsByClassName(classRating)
Set Reviews = HTMLDoc.getElementsByClassName(classReview)
Set MetaData = HTMLDoc.getElementsByClassName(classScore)
For index = 0 To Albums.Length - 1
Set InnerMeta = MetaData(index).parentElement.parentElement
Set InnerMeta = InnerMeta.getElementsByTagName("div")
album = Albums(index).innerText
rating = CDbl(Ratings(index).getAttribute("title"))
review = Reviews(index).innerText
releaseDate = InnerMeta(0).innerText
If InnerMeta.Length < 10 Then
genre = ""
Else
genre = InnerMeta(1).innerText
End If
sheet.Cells(row, 1) = Mid(album, InStr(1, album, " ") + 1, InStr(1, album, " - ") - InStr(1, album, ".") - 2)
sheet.Cells(row, 2) = Right(album, Len(album) - InStr(1, album, " - ") - 2)
sheet.Cells(row, 3) = rating
sheet.Cells(row, 4) = Left(review, Len(review) - 8)
sheet.Cells(row, 5) = releaseDate
sheet.Cells(row, 6) = genre
row = row + 1
Next index
Set nextPage = HTMLDoc.getElementsByClassName(classNext)
If nextPage.Length = 2 _
Or nextPage(0).innerText = "Next >" Then
page = page + 1
Else
exitFlag = True
End If
Set IE = Nothing
Loop Until exitFlag = True
MsgBox ("Done!")
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub