xpath - Getting a substring of an attribute is not working -
this html code:
<table id="laptop_detail" class="table"> <tbody> <tr> <td style="padding-left:36px" class="ha"> camera pixels </td> <td class="val">8 megapixel camera</td> </tr> </tbody> </table>
how first character "8" in chrome? approach far is:
$x('//*[@id="laptop_detail"]//tr/td[contains(. ,"camera")]/following-sibling::td[1]/text()[substring(. , 0, 2)]')
don't put function need output of predicate, instead, apply on node:
substring(//*[@id="laptop_detail"]//tr/td[contains(., "camera")]/following-sibling::td[1], 1, 1)
note in xpath, characters in string numbered 1, not 0.
also, don't need specify text()
, substring
knows should operate on strings.
btw, want 1 if number of megapixels 10? maybe
substring-before(..., ' ')
would work better?
Comments
Post a Comment