title: Web-Scraping with ExcelVBA
body: <p>How would I pull the table data from <a href="https://stats.nba.com/teams/opponent/?sort=W&amp;dir=-1" rel="nofollow noreferrer">Here</a>?</p>
  
  <p>I can see that each row is contained in a "team-name first" class. I would like to get the table into excel but using the from web option I can't see the table in the IE window. I think that VBA is the route that I need to take to get it. I tried some googling and youtube tutorials but I haven't had any success. Any help would be appreciated!</p>
  
  <p><a href="https://i.stack.imgur.com/rEIUY.png" rel="nofollow noreferrer">snip</a></p>
  
  <p>**Edit
  Sorry I thought I attached my code. The problem is it is not loading the full page. So I think that is why I can't pull the data.</p>
  
  <p><a href="https://i.stack.imgur.com/5U8aS.png" rel="nofollow noreferrer">There should be a table showing here</a></p>
  
  <pre><code>Sub FetchNBADefense()
  
  Dim IE As Object, obj As Object
  Dim r As Long, c As Long, t As Long
  Dim elemCollection As Object
  Dim eRow As Long
  
  
  Set IE = CreateObject("InternetExplorer.Application")
  
  With IE
  
  .Visible = True
  .navigate ("https://stats.nba.com/teams/opponent/?sort=W&amp;dir=-1")
  
  
  
  While IE.readyState &lt;&gt; 4
      DoEvents
  Wend
  
  ThisWorkbook.Sheets("TeamDefenses").Range("A1:M60").ClearContents
  Set elemColleciton = IE.document.getElementsByTagName("team-name first")
  For t = 0 To (elemCollection.Length - 1)
      For r = 0 To (elemCollection(t).Rows.Cells.Length - 1)
          For c = 0 To (elemCollection(t).Rows(r).Cells.Length - 1)
          eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
  
          ThisWorkbook.Worksheets(1).Cells(eRow, c + 1) = elemCollection(t).Rows(r).Cells(c).innerText
          Next c
      Next r
  Next t
  
  End With
  Range("A1:M60").Columns.AutoFit
  'Clear memory
  Set IE = Nothing
  
  End Sub
  </code></pre>
  
  <p>***New code: What am I missing? I see that it is "resultSet" instead of "resultSets" but still getting and Runt-time error '424': Object required</p>
  
  <pre><code>Option Explicit
  
  Public Sub FetchNBAplayerpts()
  
  Range("A1").Select
  Range(Selection, Selection.End(xlToRight)).Select
  Range(Selection, Selection.End(xlDown)).Select
  Selection.ClearContents
  
  Dim json As Object
  With CreateObject("MSXML2.XMLHTTP")
      .Open "GET", "https://stats.nba.com/stats/leagueLeaders?LeagueID=00&amp;PerMode=PerGame&amp;Scope=S&amp;Season=2018-19&amp;SeasonType=Regular+Season&amp;StatCategory=PTS", False
      .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
      .send
      Set json = JsonConverter.ParseJson(.responseText)("resultSet")(1)
  End With
  Dim headers As Object, header As Variant, headerOutput(), i As Long, rowInfo As Object, iRow As Object
  Set headers = json("headers")
  Set rowInfo = json("rowSet")
  ReDim headerOutput(1 To headers.Count)
  For Each header In headers
      i = i + 1
      headerOutput(i) = header
  Next
  
  Dim rowData(), r As Long, c As Long, Item As Variant
  ReDim rowData(1 To rowInfo.Count, 1 To UBound(headerOutput))
  
  For Each iRow In rowInfo
      r = r + 1: c = 1
      For Each Item In iRow
          rowData(r, c) = Item
      c = c + 1
      Next
  Next
  
  With ThisWorkbook.Worksheets("PlayerPts")
      .Cells(1, 1).Resize(1, UBound(headerOutput)) = headerOutput
      .Cells(2, 1).Resize(UBound(rowData, 1), UBound(rowData, 2)) = rowData
  End With
  
  End Sub
  </code></pre>