So I'm trying to scrape historic score data from masseyratings.com, and then parse it using a JSON VBA parser. I'm running into issues defining the JSON fields to pull out, I get a runtime error 13 type mismatch on the underlined line of code below. The JSON data for this query looks like this Online JSON Viewer . I want to pull third level information from DI. I have a coworker who scrapes the site using python and his syntax for JSON fields was fairly similar to what I'm using, I just can't get mine to work. Any help would be appreciated. My code currently is: (you can ignore the if statement for colOut, I haven't determined in what way I want to loop/paste the data yet)
Rich (BB code):
Sub json_parsed_massey_query()
Dim wbk As Workbook, wksht As Worksheet
Dim http As Object, JSON As Object
Dim teamID As String, teamSzn As String
Set wbk = Workbooks("massey_scores_scraper")
Set wksht = wbk.Sheets("Scraper_Inputs")
Set http = CreateObject("MSXML2.XMLHTTP") 'or ("winhttp.winhttprequest.5.1")?
lastrow0 = Cells(rows.Count, 3).End(xlUp).Row
i = 2
x = 0
colOut = 5
wksht.Activate
For Each rng In wksht.Range("c2:c" & lastrow0)
teamID = rng.Value
teamSzn = Range("D2").Value
http.Open "get", "http://www.masseyratings.com/teamjson.php?t=" & teamID & "&s=" & teamSzn & "", False
http.Send
Set JSON = ParseJson(http.ResponseText)
For Each Item In JSON
ActiveSheet.Cells(i, colOut).Value = Item("DI")("x")("0")
ActiveSheet.Cells(i, colOut).Value = Item("DI")("x")("1")
ActiveSheet.Cells(i, colOut).Value = Item("DI")("x")("2")
ActiveSheet.Cells(i, colOut).Value = Item("DI")("x")("3")("0")
ActiveSheet.Cells(i, colOut).Value = Item("DI")("x")("3")("4")
i = i + 1
x = x + 1
If colOut = 14 Then
colOut = 5
Else: colOut = colOut + 1
End If
Next Item
Next rng
End Sub