这是我的代码:
plantas = tree.xpath('//td[contains(text(),"terreno") or text[not(contains(text(),"terreno"))]]/preceding-sibling::td[1]/text()')
我如何使我的xpath抓住“ terreno”一词之前的值,或者即使没有单词也能抓住它?我上面的代码无法正常工作。
在下面的图像中,第二个没有抓住“ 1 planta”
这里是您需要的XPath(因为上一个似乎不一致):
//td[@class="tituloresult"]/following::td[@style and contains(text(),"planta")]
在目标website的前10页上完美工作。
注意:XPath表达式将排除突出显示的广告。这样一来,每页您将获得22到24个结果。
编辑:对于表面积:
//td[@class="tituloresult"]/following::td[@style and contains(text(),"terreno")]
或(包括无文字的元素):
//td[@class="tituloresult"]/following::td[@style][3]