title: How to loop through a page with multiple objects
body: <p>I'm trying to make a scraper for a market website that lists their content in a weird way.
  For each item on the list, I have to click it to find the price, and once I've clicked it and return after the data has been parsed, the order of the list of items might have changed.</p>
  
  <p>The is no specific way to refer to each "link" using Watir, so to actually successfully parse the price of all the items in an orderly fashion is outside of my knowledge.</p>
  
  <p>I use Watir to access an item <code>rb browser.element(:text =&gt; 'ItemName').click</code>.  That is fine if it was just the one item I wanted to parse data from using Nokogiri. </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div id="market" class="itemList active" style="height: 396px;" data-category="30"&gt;
      &lt;div class="item" data-mainkey="4601" data-count="40503" data-grade="0"&gt;
          &lt;div class="thumbImg" style="background-image: url(&amp;quot;https://akamai-webcdn.kgstatic.net/TradeMarket/Common/item/4601.png&amp;quot;)"&gt;&lt;/div&gt;
          &lt;div class="content"&gt;&lt;p&gt;Ash Timber&lt;/p&gt;&lt;p class="gray"&gt;&lt;/p&gt;&lt;/div&gt;
          &lt;div class="count"&gt;40503&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="item" data-mainkey="4602" data-count="266" data-grade="0"&gt;
      &lt;div class="thumbImg" style="background-image: url(&amp;quot;https://akamai-webcdn.kgstatic.net/TradeMarket/Common/item/4602.png&amp;quot;)"&gt;&lt;/div&gt;
      &lt;div class="content"&gt;&lt;p&gt;Maple Timber&lt;/p&gt;&lt;p class="gray"&gt;&lt;/p&gt;&lt;/div&gt;
      &lt;div class="count"&gt;266&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>That is how the list would look, except it's a few hundred more articles.</p>
  
  <pre class="lang-rb prettyprint-override"><code>browser.element(:text =&gt; 'Materials').click
  sleep 2
  browser.element(:text =&gt; 'Wood').click
  sleep 2
  browser.element(:text =&gt; 'Ash Timber').click
  sleep 2
  
  
  page = Nokogiri::HTML(browser.html)
  page.xpath('/html/body/div/div[1]/main/div[1]/div[2]/div[2]/p[1]').each do |nc|
    @name = (nc).text
    puts @name
  end
  </code></pre>
  
  <p>Is there a way to iterate through each item based on their "data-mainkey", since that is the identifier of the item from what I've seen.</p>
  
  <p>This is currently the project and it outputs the name of the item just fine.</p>
  
  <p>I would like the project to go through the list of articles, enter each and parse out the value to an array and show the result, but I have no clue how to approach this.</p>