Well, obviously the XPath won't work, there's no <p> on the page. XPath is pretty intuitive, it should be obvious what it is looking for. The example says find a <p> with the text "earthworms" in it, and find a <strong> inside that <p>. Since you've got no <p>, get rid of the //p[contains()] part. If that's the only <strong> on the page, you can just use //strong to get it.
On Sat, Oct 24, 2009 at 7:48 AM, Stuer Michael <[email protected]> wrote: > > Well i just tried the piece of code erik posted but i got some errors > > i tried the script as follows > > var ew = document.evaluate("//p[contains(.,'earthworms')]/ > strong",document,null,9,null).singleNodeValue; > > if(!ew) return; // no earthworms node found > > ew = ew.innerHTML*1; > > alert("Number of earthworms is "+ew); > > but i got this error: SyntaxError: return not in function > in eval() line 0 > > and then i tried withouth the return line and got this: > > TypeError: ew is null > > maybe it'll help if i post more of the source page. > > > <table id="megaTable2" cellpadding="0" cellspacing="0"> > <tr> > <td rowspan="2" id="leftSpacing"> > </td> > <td id="contentBox" height="500" valign="top"> > <center> <table border="0" cellspacing="0" > cellpadding="2" > width="100%"> > > <tr> > <td width=95% class="heading_box"> > Fishing Fever > </td> > </tr> > </table><br>Here in the lake district, we offer you the chance to > compete in our famous fishing fever competition. All you need is an > earthworm to use as bait, and a good sense of where in the lake you'll > find the largest catch.<br><br>Your current fishing fever score is > <strong>31</strong><br><br>You currently have <strong>98</strong> > earthworms. Earn more at <a href='dirtdigger.php'>Dirt Digger</ > a><br><br>Pick a location, cast your line, and see what you reel in! > <br><br><form method='post' action='/fishingfever.php?act=fish'><input > type='image' src='http://www.pokeplushies.com/images/games/ > cf_lake.jpg' style='cursor:crosshair;'><input type='hidden' > name='code' value='74848'></form><br><br><a href='/fishingfever.php? > act=topfishers'>Click here to see who the top fishers are!</a> > </ > center> > > </td> > <td rowspan="2" width="160" valign="top"> > <center> > > > > On Oct 23, 8:30 pm, Erik Vold <[email protected]> wrote: >> A regex will work, but xpath expression is better in general, or you >> could write an xpath expression with some >> regexhttp://www.regular-expressions.info/xpath.html >> which is probably better if you are going to use regex at all. >> >> Using Gordon's xpath exp the js to get your earthworm count should be >> like: >> var ew=document.evaluate("//p[contains(.,'earthworms')]/ >> strong",document,null,9,null).singleNodeValue; >> if(!ew) return;// no earthworms node found >> ew=ew.innerHTML*1; >> alert("Number of earthworms is "+ew); >> >> Where the last line that alerts the earthworm count is something more >> useful. >> >> Erik >> >> On Oct 23, 6:36 am, Gordon Pettey <[email protected]> wrote: >> >> > On Fri, Oct 23, 2009 at 4:33 AM, 杨大成 <[email protected]> wrote: >> > > i don't see any js can operate <strong> , >> > > how about regex? >> >> > I repeat: XPath. No need for a regex. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en -~----------~----~----~----~------~----~------~--~---
