Feixiang Sun
Feixiang Sun

Reputation: 117

How to use XPath to select following-sibling

<tr>
                        <td width="120" align="right" class="tit">application:</td>
                        <td style="width:345px;word-break:break-all;">




                                <a  style="text-decoration: underline; color: #0066ff; cursor: pointer"
                                        href="javascript:_search('pa',  '<font color=red>PartA</font>PartB');"> <font color=red>PartA</font>PartB</a>;



                        </td>
                    </tr>
                    <tr>

In above code, I use part of the name (Part A) to search result, how can I get the whole name which combines PartA and PartB. I use below code and just get PartA and nothing

html.xpath('//td[contains(text(),"application")]/following-sibling::td[1]/a/font/text()')[0]
html.xpath('//td[contains(text(),"application")]/following-sibling::td[1]/a/text()')[0]

Upvotes: 0

Views: 60

Answers (1)

E.Wiest
E.Wiest

Reputation: 5915

You need to fix your second XPath accordingly :

//td[contains(text(),"application")]/following-sibling::td[1]/a/text()[normalize-space()]

Output : Part B

To select the two items directly you can use :

//td[contains(text(),"application")]/following-sibling::td[1]//text()[normalize-space()]

To combine them :

concat(//td[contains(text(),"application")]/following-sibling::td[1]/a/font/text(),//td[contains(text(),"application")]/following-sibling::td[1]/a/text()[normalize-space()])

or

string(//td[contains(text(),"application")]/following-sibling::td[1]/a)

Output : PartAPartB

Upvotes: 1

Related Questions