开发者

help me with xpath please [duplicate]

开发者 https://www.devze.com 2023-02-16 06:56 出处:网络
This question alrea开发者_如何学JAVAdy has an answer here: Closed 11 years ago. Possible Duplicate:
This question alrea开发者_如何学JAVAdy has an answer here: Closed 11 years ago.

Possible Duplicate:

if you know xpath then please help?

hi, so here is the html code

<html>
<body>
<table>
<tr>
Test
</tr>
<tr> 
<td>
<a href = "google.com">
Google
</a>
</td>
</tr>

<tr>
<td> test1</td>
<td> 
<a href = "yahoo.com"> Yahoo!</a>
</td>
</tr>


</tr>
</table>

</body>
</html>

so now I want the text Google and Yahoo!

how can I get that

here is what I wrote

table[1]/tr[1]/td[2]

I dont't know what is happening but nothing is showing up...

thanks


The XPath you are looking for is as follows:

For Google

/html/body/table/tr[2]/td/a/text()

For Yahoo

/html/body/table/tr[3]/td/a/text()

As the title is contained in a 'a' element and you use the text() node type test to get the text value of the 'a' element.

Actually I think your html has a additional </tr> at the bottom which makes it invalid


If you know there will always be that number and type of elements:

/html/body/table/tr/td/a/

A more generic way is:

html//a
0

精彩评论

暂无评论...
验证码 换一张
取 消