title: scraping data from website using vba - problem
body: <p>I'm trying to get the address, facility type and some other data from every facility on this search. I'm able to get the search results and the list of facilities but I cannot figure out how to get the data from the page.</p>
  <p>EDIT
  i've applied the suggestiong in the answer, here's the new code and the OBJECT REQUIRED error is at the DEBUG line
  I'm trying to click on each link and get the name, address, facility type and whatever other data is on that page</p>
  <pre><code>Sub Test()
      Dim ie2 As New InternetExplorer
      'Set ie = New InternetExplorerMedium
  
      With ie2
          .Visible = True
          .navigate &quot;https://healthapps.state.nj.us/facilities/fsSetSearch.aspx?by=county&quot;
  
          FacType = &quot;Long-Term Care (Nursing Homes)&quot;
          While .Busy Or .ReadyState &lt; 4: DoEvents: Wend
  
          With .Document
              .querySelector(&quot;#middleContent_cbType_0&quot;).Click
              .querySelector(&quot;#middleContent_btnGetList&quot;).Click
          End With
              
          While .Busy Or .ReadyState &lt; 4: DoEvents: Wend
              
  
          Pause (2)
          
          Dim list2 As Object, i2  As Long, line1 As String, line2 As String
  
          Set list2 = .Document.querySelectorAll(&quot;[href*='fsFacilityDetails.aspx?item=']&quot;)
          
          For i2 = 0 To list2.Length - 1
              list2.Item(i2).Click
              Debug.Print .Document.querySelector(&quot;.infotable tr:nth-of-type(3) td + td&quot;).innerText
              
              While .Busy Or .ReadyState &lt; 4: DoEvents: Wend
  
              Pause (2)
  
              address = Replace(Replace(Replace(line1 &amp; &quot; &quot; &amp; line2, &quot;&lt;span id=&quot; &amp; Chr(34) &amp; &quot;middleContent_lbAddress&quot; &amp; Chr(34) &amp; &quot;&gt;&quot;, &quot;&quot;), &quot;&lt;br&gt;&quot;, &quot;, &quot;), &quot;&lt;/span&gt;&quot;, &quot;&quot;)
  
              WriteTable .Document.getElementsByTagName(&quot;table&quot;)(3), .Document.getElementById(&quot;middleContent_Menu1&quot;).innerText
  
              .Navigate2 .Document.URL
              While .Busy Or .ReadyState &lt; 4: DoEvents: Wend
              Set list2 = .Document.querySelectorAll(&quot;[href*='fsFacilityDetails.aspx?item=']&quot;)
  
          Next
          .Quit                                    '
      End With
  
  End Sub
  </code></pre>
  <p>I get the OBJECT REQUIRED error at this line</p>
  <p><strong>Address = Replace(Replace(Replace(.Document.getElementById(&quot;middleContent_lbAddress&quot;).outerHTML, &quot;&lt;span id=&quot; &amp; Chr(34) &amp; &quot;middleContent_lbAddress&quot; &amp; Chr(34) &amp; &quot;&gt;&quot;, &quot;&quot;), &quot;<br>&quot;, &quot;, &quot;), &quot;&quot;, &quot;&quot;)</strong></p>
  <p>but I'm pretty sure that I'm using the wrong way to get the data anyway. So, even without the error I wouldn't have given me what I need.</p>
  <pre><code>Sub Test()
      Dim ie2 As New InternetExplorer
      'Set ie = New InternetExplorerMedium
  
      With ie2
          .Visible = False
          .navigate &quot;https://healthapps.state.nj.us/facilities/fsSetSearch.aspx?by=county&quot;
  
          While .Busy Or .ReadyState &lt; 4: DoEvents: Wend
  
          With .Document
              .querySelector(&quot;#middleContent_cbType_0&quot;).Click
              .querySelector(&quot;#middleContent_btnGetList&quot;).Click
          End With
              
          While .Busy Or .ReadyState &lt; 4: DoEvents: Wend
              
          Dim list2 As Object, i2  As Long
          Set list2 = .Document.querySelectorAll(&quot;#main_table&quot;)
               
          For i2 = 0 To list2.Length - 1
              list2.Item(i2).Click
  
              While .Busy Or .ReadyState &lt; 4: DoEvents: Wend
  
              Pause (2)
      
              If .Document.getElementById(&quot;middleContent_lbResultTitle&quot;) Is Nothing Then
                  Pause (5)
              End If
  
              If .Document.getElementById(&quot;middleContent_lbResultTitle&quot;).outerHTML Like &quot;*Long-Term Care Facility*&quot; Then
                  FacType = &quot;Long-Term Care (Nursing Homes)&quot;
              End If
  
              Address = Replace(Replace(Replace(.Document.getElementById(&quot;middleContent_lbAddress&quot;).outerHTML, &quot;&lt;span id=&quot; &amp; Chr(34) &amp; &quot;middleContent_lbAddress&quot; &amp; Chr(34) &amp; &quot;&gt;&quot;, &quot;&quot;), &quot;&lt;br&gt;&quot;, &quot;, &quot;), &quot;&lt;/span&gt;&quot;, &quot;&quot;)
  
              WriteTable .Document.getElementsByTagName(&quot;table&quot;)(3), .Document.getElementById(&quot;middleContent_Menu1&quot;).innerText
  
  
              .Navigate2 .Document.URL
              While .Busy Or .ReadyState &lt; 4: DoEvents: Wend
              Set list2 = .Document.querySelectorAll(&quot;#main_table&quot;)
  
          Next
          .Quit                                    '
      End With
  End Sub
  </code></pre>