Scrapy: skip classless span with css selectors

Question:

<div class="classA">
   <span class="classB">hello</span>
   <span aria-hidden="true">world</span>
   <span>I want this text</span>
</div>

I want to get the text in the 3rd span using CSS selectors. My problem is that I don’t know how to skip the second span as it doesn’t have a class. Maybe we could use the aria-hidden="true"?

So far I have this:

response.css('div.classA > span:not([class^="classB"])').get()
Asked By: Soffamumie

||

Answers:

If you are always trying to select the 3rd span tag then you can use the nth-child() selector.

response.css('div > span:nth-child(3)').get()
Answered By: E Joseph
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.