In Python, you could do list[-1] to get the last element. So, how do you do it in
XPATH? Say, I want to get the last link in the navigation that is made up of lots of
<li\>s. To do that, you can use the following xpath:
last_link_xpath = '//ul[@class="pagination"]/li[last()-1]/a/text()'
Now, on to slicing, there’s a very useful StackOverflow question regarding this. To summarize it:
in Python is equivalent to:
/*/bar[position() >= 5 and not(position() >= 10)]
Happy XPATHing and using Scrapy with it.