How to get last OPTION from SELECT list using XPath - Scrapy

徘徊边缘 提交于 2019-12-19 09:14:23

问题


I am using this selector but it is giving error

//*[@id="quantity"]/option/[last()-1]

How do I select last OPTION?

I am using Scrapy Framework.


回答1:


You have an extra / before the [ making the XPath expression invalid. Remove it:

//*[@id="quantity"]/option[last()-1]

Note that you can also solve it using Python/Scrapy:

response.xpath('//*[@id="quantity"]/option')[-1].extract()

Or, in a CSS selector form:

response.css('#quantity option:last-child').extract_first()
response.css('#quantity option')[-1].extract()


来源:https://stackoverflow.com/questions/39939553/how-to-get-last-option-from-select-list-using-xpath-scrapy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!