title: How to parse src from img tag in VBA
body: <p>I have a question relating to HTML parsing. I have a website with some products and I would like to catch the URL from images into my current spreadsheet.
  This spreadsheet is quite big but contains ItemNbr in 3rd column, I expect the URL in the 27th column and one row corresponds to one product (item). </p>
  
  <p>My idea is to fetch the URL of 'regular' OR 'large' OR 'verylarge' images (It doesn't really matter). Here is the structure of the website (among various other div):</p>
  
  <pre><code>&lt;div id="MainDisplay" class="miMaindisplay"&gt;
      &lt;a href="http://www.example.com/verylarge/12425/nl" id="ctl00_PageContent_MultiImage_jqzoom" class="loupe"&gt;
          &lt;div class="zoomPad"&gt;
              &lt;img src="http://www.example.com/regular/12425/nl" id="ctl00_PageContent_MultiImage_PreviewImage" class="miPreviewImage"&gt;
              &lt;div class="zoomPup"&gt;&lt;/div&gt;
              &lt;div class="zoomWindow"&gt;
                  &lt;div class="zoomWrapper"&gt;
                      &lt;div class="zoomWrapperTitle"&gt;&lt;/div&gt;
                      &lt;div class="zoomWrapperImage"&gt;
                          &lt;img src="http://www.example.com/large/12425/nl"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="zoomPreload"&gt;Loading zoom&lt;/div&gt;
          &lt;/div&gt;
      &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I could get the URL in the JS console with this line:</p>
  
  <pre><code>document.getElementById('ctl00_PageContent_MultiImage_PreviewImage').src;
  </code></pre>
  
  <p>And the answer is:</p>
  
  <pre><code>http://www.example.com/regular/12425/nl
  </code></pre>
  
  <p>But without success in VBA. Here is my code snippet:</p>
  
  <pre><code>Sub ParseImage()
  
      Dim Cell As Integer
      Dim ItemNbr As String
  
      Dim AElement As Object
      Dim AElements As IHTMLElementCollection
  
      Dim IE As MSXML2.XMLHTTP60
      Set IE = New MSXML2.XMLHTTP60
  
      Dim HTMLDoc As MSHTML.HTMLDocument
      Dim HTMLBody As MSHTML.HTMLBody
  
      Set HTMLDoc = New MSHTML.HTMLDocument
      Set HTMLBody = HTMLDoc.body
  
      For Cell = 1 To 5                            'I iterate through the file row by row
  
          ItemNbr = Cells(Cell, 3).Value           'ItemNbr are in the 3rd Column of my spreadsheet
  
          IE.Open "GET", "http://www.example.com/?item=" &amp; ItemNbr, False
          IE.send
  
          While IE.ReadyState &lt;&gt; 4
              DoEvents
          Wend
  
          HTMLBody.innerHTML = IE.responseText
  
          Set AElements = HTMLDoc.getElementsByTagName("a")
          For Each AElement In AElements
              If AElement.id = "ctl00_PageContent_MultiImage_PreviewImage" Then
                  Cells(Cell, 27) = AElement.src     'I write URL in the 27th column
              End If
          Next AElement
  
          Application.Wait (Now + TimeValue("0:00:2"))
  
  Next Cell
  </code></pre>
  
  <p>End Sub</p>
  
  <p>I obviously included some references as follows:</p>
  
  <p><img src="https://i.stack.imgur.com/hlUz0.png" alt="References"></p>
  
  <p>Thank you for your help!</p>