title: how to use getelementsbytagname to extract LI value
body: <p>I am trying to search for a product on amazon.com and extract the asin for the item. The asin is hidden in the li under data-asin tag. my excel macro currently runs through all the search tag options and checks amazon 1 by 1 and gathers the product price. But I need this function to also gather the asin for each item</p>
  
  <p>Code Below:</p>
  
  <pre><code>Sub SearchGoogle()
  Dim ie As Object
  Dim form As Variant
  Dim button As Variant
  Dim LR As Integer
  Dim var As String
  Dim var1 As Object
  Dim var2 As Object
  LR = Cells(Rows.Count, 1).End(xlUp).Row
  For x = 2 To LR
  var = Cells(x, 1).Value
  Set ie = CreateObject("internetexplorer.application")
  ie.Visible = True
   With ie
  .Visible = True
  .navigate "https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&amp;field-keywords=" &amp; Range("azAsin")
  While Not .readyState = READYSTATE_COMPLETE
  Wend
  End With
  'Wait some to time for loading the page
  While ie.Busy
  DoEvents
  Wend
  Application.Wait (Now + TimeValue("0:00:02"))
  
  While ie.Busy
  DoEvents
  Wend
  
  Application.Wait (Now + TimeValue("0:00:02"))
  'Set var1 = ie.document.getElementsByClassName("sx-price-whole")
  'Cells(x, 2).Value = var1(0).textContent
  Set var2 = ie.document.getElementById("result_0").getelementsbytagname("data-asin")
  MsgBox var2(0).textContent
  'Cells(x, 3).Value = var2().innerText
  ie.Quit
  Set ie = Nothing
  Next x
  End Sub
  </code></pre>
  
  <p>HTML CODE from amazon.com when i search for a specific item:</p>
  
  <pre><code>&lt;li id="result_0" data-result-rank="0" data-asin="B006RN77MI" data-action="sx-detail-display-trigger" class="s-result-item s-result-card-for-container a-declarative celwidget  "&gt;&lt;div class="s-item-container" style="height: 367px;"&gt;&lt;div class="a-row a-spacing-top-micro a-spacing-micro"&gt;&lt;div class="a-row sx-badge-region"&gt;&lt;div class="a-row a-spacing-large"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-base"&gt;&lt;div aria-hidden="true" class="a-column a-span12 a-text-center s-position-relative"&gt;&lt;a class="a-link-normal a-text-normal" href="https://www.amazon.com/Ameda-Platinum-Breast-Grounded-Power/dp/B006RN77MI/ref=sr_1_1_a_it?ie=UTF8&amp;amp;qid=1515781416&amp;amp;sr=8-1&amp;amp;keywords=B006RN77MI"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/41NrM6wVJTL._AC_US200_.jpg" srcset="https://images-na.ssl-images-amazon.com/images/I/41NrM6wVJTL._AC_US200_.jpg 1x, https://images-na.ssl-images-amazon.com/images/I/41NrM6wVJTL._AC_US300_FMwebp_QL65_.jpg 1.5x, https://images-na.ssl-images-amazon.com/images/I/41NrM6wVJTL._AC_US400_FMwebp_QL65_.jpg 2x, https://images-na.ssl-images-amazon.com/images/I/41NrM6wVJTL._AC_US500_FMwebp_QL65_.jpg 2.5000x" width="200" height="200" alt="Product Details" class="s-access-image cfMarker" data-search-image-load=""&gt;&lt;/a&gt;&lt;div class="a-section a-spacing-none a-text-center"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;div class="a-row a-spacing-mini"&gt;&lt;a class="a-link-normal s-access-detail-page  s-color-twister-title-link a-text-normal" title="Ameda Platinum Breast Pump with Grounded Power Cord" href="https://www.amazon.com/Ameda-Platinum-Breast-Grounded-Power/dp/B006RN77MI/ref=sr_1_1_a_it?ie=UTF8&amp;amp;qid=1515781416&amp;amp;sr=8-1&amp;amp;keywords=B006RN77MI"&gt;&lt;h2 data-attribute="Ameda Platinum Breast Pump with Grounded Power Cord" data-max-rows="0" class="a-size-base s-inline  s-access-title  a-text-normal"&gt;Ameda Platinum Breast Pump with Grounded Power Cord&lt;/h2&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;a class="a-link-normal a-text-normal" href="https://www.amazon.com/Ameda-Platinum-Breast-Grounded-Power/dp/B006RN77MI/ref=sr_1_1?ie=UTF8&amp;amp;qid=1515781416&amp;amp;sr=8-1&amp;amp;keywords=B006RN77MI"&gt;&lt;span class="a-offscreen"&gt;$1,995.00&lt;/span&gt;&lt;span aria-hidden="true" class="a-color-base sx-zero-spacing"&gt;&lt;span class="sx-price sx-price-large"&gt;
                          &lt;sup class="sx-price-currency"&gt;$&lt;/sup&gt;
                          &lt;span class="sx-price-whole"&gt;1,995&lt;/span&gt;
                          &lt;sup class="sx-price-fractional"&gt;00&lt;/sup&gt;
                      &lt;/span&gt;
                  &lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;span class="a-size-small a-color-price"&gt;Only 1 left in stock - order soon.&lt;/span&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-top-mini a-spacing-none"&gt;&lt;span name="B006RN77MI"&gt;
  </code></pre>