0
<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()

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.