title: VBA/DOM - Get elements based on attribute
body: <p>Excel 2013 on Windows 7. <code>XPath</code>/<code>Javascript</code>/<code>jQuery</code> is out of scope.</p>
  
  <p>I am trying to iterate over select <code>div</code> elements in a page, namely elements that have a specific <code>data-level</code> attribute.</p>
  
  <p>My current approach is <a href="https://stackoverflow.com/a/20142333/4604845">similar to this</a>, but I was unable to find a non-manual way to select elements based on attributes. The closest I came was something like:</p>
  
  <pre><code>With CreateObject("WINHTTP.WinHTTPRequest.5.1")
      .Open "GET", url, False
      .Send
      pHTML.body.innerHTML = .ResponseText
  End With
  
  Set eCollection = pHTML.getElementsByClassName("chapter").getElementsByTagName("div")
  
  For i = 0 To eCollection.Length
      If eCollection(i).getAttribute("data-level") &gt;= 0 Then ' Throw cake
  Next i
  </code></pre>
  
  <p>This solution, while I am sure it is viable (if unelegant), seems sub-optimal if only for how big the loop is going to end up being when I start looking for specific elements and sequences of elements within <em>these elements</em>.</p>
  
  <p>So I am looking for a way to do something like this:</p>
  
  <pre><code>For Each pElement In pHTML.getElementsByClassName("chapter").getElementsByTagName("div").getElementsByAttribute("data-level")
      ' Throw cake at the element
  Next
  </code></pre>
  
  <p><strong>I'm aware that there is no method <code>getElementsByAttribute</code>, hence the question.<br>
  Is there some approach here that I am blind to, or am I locked to manual iteration?</strong></p>
  
  <p>Alternatively, if I swap my current approach for creating an IE instance, á la <a href="https://stackoverflow.com/q/31313816/4604845">this answer</a>, could I concievably use <code>querySelectorAll</code> to end up with something resembling the result I have outlined above?</p>