How to get last OPTION from SELECT list using XPat

2019-02-19 01:15发布

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.

标签: python scrapy
1条回答
不美不萌又怎样
2楼-- · 2019-02-19 02:08

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()
查看更多
登录 后发表回答