I'm writing a Greasemonkey script, and I wanted to change the text of a forum post on a phpBB2 forum by using XPath to select the body of the post that occurs after a certain username, but the whole thing is a giant mess of tables.
<tr>
<td>
<span class="name">
<a>
<b>username</b>
</span>
<span></span>
</td>
<td>
<table>
<tbody>
<tr></tr>
<tr></tr>
<tr>
<td>
<span class="postbody">text of post</span>
<span开发者_如何学编程></span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
I need to get the postbody span that happens after the username in the b tag equals a certain name, and then mess with the text. Here is how I am trying to do it:
var postguy = document.evaluate('fffffff', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < postguy.snapshotLength; i++) {
thisLink = postguy.snapshotItem(i);
//then do something with the post
}
I'd do it like this:
//tr[.//b/text()='username']//span[@class='postbody']
To align with the comments, you could narrow things down a bit by restricting where the b
tag is:
//tr[.//span[@class='name']//b/text()='username']//span[@class='postbody']
Damn it! I was in too much of a hurry for those @
s. Gotta slow down and smell the @
s sometimes.
精彩评论