我正在使用这个选择器,但它给出了错误
// * [@ ID = “数量”] /选项/ [最后() – 1]
如何选择最后一个OPTION?
我正在使用Scrapy Framework.
最佳答案 你有一个额外/之前[使XPath表达式无效.去掉它:
//*[@id="quantity"]/option[last()-1]
请注意,您也可以使用Python / Scrapy解决它:
response.xpath('//*[@id="quantity"]/option')[-1].extract()
或者,在CSS选择器表单中:
response.css('#quantity option:last-child').extract_first()
response.css('#quantity option')[-1].extract()