title: How to iterate through nodes in scrapy using python
body: <p>I am trying to scrape a website and the content of the html looks something like this</p>
  
  <pre><code>&lt;div class="panel-heading" role="tab" id="heading727654"&gt;
              &lt;h4 class="panel-title"&gt;
                  &lt;a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse727654" aria-expanded="false" aria-controls="collapse727654"&gt;
                      &lt;div class="product-name"&gt;
                          &lt;span class="product-title"&gt;
                              Aubrey&lt;br&gt;&lt;i&gt;AGE DEFYING THERAPY CLEANSER 3.4 OZ&lt;/i&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="product-price"&gt;
                          &lt;span&gt;
                              $10.99 / 3.40 OZ 
                          &lt;/span&gt;
                  &lt;/a&gt;
              &lt;/h4&gt;
  &lt;/div&gt;
  &lt;div class="panel-heading" role="tab" id="heading727655"&gt;
              &lt;h4 class="panel-title"&gt;
                  &lt;a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse727655" aria-expanded="false" aria-controls="collapse727654"&gt;
                      &lt;div class="product-name"&gt;
                          &lt;span class="product-title"&gt;
                              Aubrey&lt;br&gt;&lt;i&gt;AGE DEFYING THERAPY LIQUID&lt;/i&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="product-price"&gt;
                          &lt;span&gt;
                              $12.99 / 4.40 OZ 
                          &lt;/span&gt;
                  &lt;/a&gt;
              &lt;/h4&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My python code snippet to extract this is something like </p>
  
  <pre><code>def parse(self, response):
          filename = response.url.split("/")[-2] + '.html'
          with open(filename, 'wb') as f:
              for node in response.xpath('//div[re:test(@class, "panel-heading")]'):
                  print node.xpath('//span[re:test(@class, "product-title")]//text()').extract()
                  print node.xpath('//span[re:test(@class, "product-price")]//text()').extract()
  </code></pre>
  
  <p>When I run the above scrapy code in Python, I am not getting the expected output, the same content is being repeated 100 times. Can someone help me with this?</p>