title: VBA Object Variable Not Set - HTML Scraping
body: <p>I am trying to scrape google, and am having trouble pulling multiple elements from HTML Segments. Google presents each search result as a "card" class. I keep getting the Object Variable Not Set error when I run the following code.</p>
  
  <pre><code>&gt; Option Explicit
  &gt; 
  &gt; Sub StatusLetter()
  &gt;     SearchandScrape ("Apple") End Sub
  &gt; 
  &gt; Sub SearchandScrape(URL As String)
  &gt;     Dim IE As New SHDocVw.InternetExplorer
  &gt;     Dim HTMLDoc As MSHTML.HTMLDocument
  &gt;     Dim HTMLCard As MSHTML.IHTMLElement
  &gt;     Dim HTMLCards As MSHTML.IHTMLElementCollection
  &gt;     Dim Temp As MSHTML.IHTMLElement
  &gt;     Dim scrapedCard As New card
  &gt;     
  &gt;     IE.Visible = True
  &gt;     IE.navigate "https://www.google.com/search?q=" &amp; URL &amp; "&amp;tbm=nws&amp;source=lnt&amp;tbs=qdr:d&amp;sa=X&amp;ved=0ahUKEwjf_LHL1bngAhXqQ98KHTs2D4QQpwUIHw&amp;biw=1282&amp;bih=893&amp;dpr=1"
  &gt;         
  &gt;     Do While IE.readyState &lt;&gt; READYSTATE_COMPLETE
  &gt;     Loop
  &gt;     
  &gt;     Set HTMLDoc = IE.Document
  &gt;     
  &gt;     Set HTMLCards = HTMLDoc.getElementsByClassName("card")
  &gt;     
  &gt;     For Each HTMLCard In HTMLCards
  &gt;         Temp = HTMLCard.getElementsByTagName("h3")(0)
  &gt;         Debug.Print Temp.innerText
  &gt;     Next End Sub
  </code></pre>
  
  <p>I get the Error in the for each loop. I want to be able to pull the text of 3 tags that is stored in a HTML segment. 2 of them are spans and the third is the h3 for each card in HTMLCards. Any recommendations on a fix for this. I cant seem to figure out how to correctly access these objects. Thanks!</p>