Duplicate results in Xpath and not CSS selectors in scrapy
<p>So I am playing around with scrapy through the <a href="https://doc.scrapy.org/en/latest/intro/tutorial.html" rel="nofollow">tutorial</a>. I am trying to scrape the text, author and tags of each quote in the <a href="http://quotes.toscrape.com/page/1/" rel="nofollow">companion website</a>
when using CSS selectors like mentioned there:</p>

<pre><code>for quote in response.css('div.quote'):
    print quote.css('span.text::text').extract()
    print quote.css('span small::text').extract()
    print quote.css('div.tags a.tag::text').extract()
</code></pre>

<p>I get the desired result (i.e: print of each text, author and quotes once).
But once using Xpath selectors like this:</p>

<pre><code>for quote in response.xpath("//*[@class='quote']"):
    print quote.xpath("//*[@class='text']/text()").extract()
    print quote.xpath("//*[@class='author']/text()").extract()
    print quote.xpath("//*[@class='tag']/text()").extract()
</code></pre>

<p>I get duplicates results! </p>

<p>I still can't find why there is such a difference between the 2.</p>

<p>When you use // it will get all results from response. If you use .// then it scope will be limited to that selector. Try <code>.//</code> instead of <code>//</code>. It will solve your problem :-)</p>

python xpath css-selectors scrapy