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

前端 未结 1 786
温柔的废话
温柔的废话 2021-01-13 19:10

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 F

1条回答
  •  别那么骄傲
    2021-01-13 19:20

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

    0 讨论(0)
提交回复
热议问题