How to obtain a number from the site

View: New views
12 Messages — Rating Filter:   Alert me  

How to obtain a number from the site

by Stuer Michael :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


i'm currently trying to make a script in the setting of a fishing
game. but i only want the script to fish when i have earthworms.
(kinda makes sense doesn't it :p)

but i dont know how i can script this...

in the source page of the web page i found this:

You currently have <strong>95</strong> earthworms.

is there any way to make my script read this in and remember this as a
variable?

friendly greets
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by Gordon Pettey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


XPath, if there's decent markup around it. If that text is in a <p> by
itself, you could use //p[contains(.,'earthworms')]/strong and then
Number() the result.

On Thu, Oct 22, 2009 at 5:13 PM, Stuer Michael <stuermichael@...> wrote:

>
> i'm currently trying to make a script in the setting of a fishing
> game. but i only want the script to fish when i have earthworms.
> (kinda makes sense doesn't it :p)
>
> but i dont know how i can script this...
>
> in the source page of the web page i found this:
>
> You currently have <strong>95</strong> earthworms.
>
> is there any way to make my script read this in and remember this as a
> variable?
>
> friendly greets
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by 杨大成 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i don't see any js can operate <strong> ,
how about regex? 

2009/10/23 Stuer Michael <stuermichael@...>

i'm currently trying to make a script in the setting of a fishing
game. but i only want the script to fish when i have earthworms.
(kinda makes sense doesn't it :p)

but i dont know how i can script this...

in the source page of the web page i found this:

You currently have <strong>95</strong> earthworms.

is there any way to make my script read this in and remember this as a
variable?

friendly greets



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by Gordon Pettey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Fri, Oct 23, 2009 at 4:33 AM, 杨大成 <dacheng.y@...> 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 greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by Erik Vold-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


 A regex will work, but xpath expression is better in general, or you
could write an xpath expression with some regex http://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 <petteyg...@...> wrote:
> On Fri, Oct 23, 2009 at 4:33 AM, 杨大成 <dachen...@...> 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 greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by Stuer Michael :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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 <erikvv...@...> 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 <petteyg...@...> wrote:
>
> > On Fri, Oct 23, 2009 at 4:33 AM, 杨大成 <dachen...@...> 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 greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by Gordon Pettey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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 <stuermichael@...> 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 <erikvv...@...> 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 <petteyg...@...> wrote:
>>
>> > On Fri, Oct 23, 2009 at 4:33 AM, 杨大成 <dachen...@...> 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 greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by vBm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


He can use xpath that'll only check text nodes for needed word. Thou
if it returns more then one result ... well just find the needed
one :)

$x("//*[text()[contains(.,'earthworms')]])")


(this 'code' you can use from firebug's console and you'll see results
in it)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by cc-21 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The return only works if the chunk of code is within a function. If
you're using a current version of Greasemonkey, it should just work
(because most versions wrap the script in an anonymous function before
executing).

Alternatively, reverse the logic of the if statement and put the two
following statements inside the if block, getting rid of the return
statement entirely.

Gordon already touched on the real problem with this code, of course,
which is that the XPath is looking for <p> tags that don't exist.

On 2009-10-24 05:48, Stuer Michael 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<erikvv...@...>  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<petteyg...@...>  wrote:
>>
>>      
>>> On Fri, Oct 23, 2009 at 4:33 AM, 杨大成<dachen...@...>  wrote:
>>>        
>>>> i don't see any js can operate<strong>  ,
>>>> how about regex?
>>>>          
>>      
>>> I repeat: XPath. No need for a regex.
>>>        
> >
>
> ____________________________________________________________________________________
> Introducing Branchr
> Super Simple Advertising
> http://click.lavabit.com/?pub=78&ad=0023&url=aHR0cDovL2JyYW5jaHIuY29tLw==
> ____________________________________________________________________________________
>    


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by Stuer Michael :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


so like you guys said i removed the Pcontains thing because there is
no <p>
and when i first tried he nagged about the return again so i removed
it and therefore ended up with :

var ew=document.evaluate("//strong",document,null,
9,null).singleNodeValue;

ew=ew.innerHTML*1;

alert("Number of earthworms is "+ew);

and when i ran this i finally got output... namely my fishing fever
score (wich is a different number in <strong> a little before the one
i need. (actually the one right before it.

so how can i make him skip the first one and use the second one he
finds.

PS: i allready want to thank all of you for helping me here :p i know
i'm not the most experienced scripter but its nice that others help
you sometimes :p

friendly greets

On 24 okt, 20:46, cc <carlcl...@...> wrote:

> The return only works if the chunk of code is within a function. If
> you're using a current version of Greasemonkey, it should just work
> (because most versions wrap the script in an anonymous function before
> executing).
>
> Alternatively, reverse the logic of the if statement and put the two
> following statements inside the if block, getting rid of the return
> statement entirely.
>
> Gordon already touched on the real problem with this code, of course,
> which is that the XPath is looking for <p> tags that don't exist.
>
> On 2009-10-24 05:48, Stuer Michael 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<erikvv...@...>  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<petteyg...@...>  wrote:
>
> >>> On Fri, Oct 23, 2009 at 4:33 AM, 杨大成<dachen...@...>  wrote:
>
> >>>> i don't see any js can operate<strong>  ,
> >>>> how about regex?
>
> >>> I repeat: XPath. No need for a regex.
>
> > ____________________________________________________________________________________
> > Introducing Branchr
> > Super Simple Advertising
> >http://click.lavabit.com/?pub=78&ad=0023&url=aHR0cDovL2JyYW5jaHIuY29t...
> > ____________________________________________________________________________________
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by cc-21 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


What you're actually looking for is something a little more like this, I
think:

var ew = document.evaluate("//strong[2]", document, null, 9, null).singleNodeValue;

if (ew) {
     ew = ew.innerHTML * 1;

     alert("Number of earthworms is " + ew);
}


This works (or doesn't; I haven't actually tested the whole thing, but
it should work fine) because you can index nodes found by number
(starting at 1). Also, I stuck in the check I suggested in the last
message, to make sure you won't get any null reference errors (the if
(ew) { and }).

On 2009-10-26 15:41, Stuer Michael wrote:

> so like you guys said i removed the Pcontains thing because there is
> no<p>
> and when i first tried he nagged about the return again so i removed
> it and therefore ended up with :
>
> var ew=document.evaluate("//strong",document,null,
> 9,null).singleNodeValue;
>
> ew=ew.innerHTML*1;
>
> alert("Number of earthworms is "+ew);
>
> and when i ran this i finally got output... namely my fishing fever
> score (wich is a different number in<strong>  a little before the one
> i need. (actually the one right before it.
>
> so how can i make him skip the first one and use the second one he
> finds.
>
> PS: i allready want to thank all of you for helping me here :p i know
> i'm not the most experienced scripter but its nice that others help
> you sometimes :p
>
> friendly greets
>
> On 24 okt, 20:46, cc<carlcl...@...>  wrote:
>    
>> The return only works if the chunk of code is within a function. If
>> you're using a current version of Greasemonkey, it should just work
>> (because most versions wrap the script in an anonymous function before
>> executing).
>>
>> Alternatively, reverse the logic of the if statement and put the two
>> following statements inside the if block, getting rid of the return
>> statement entirely.
>>
>> Gordon already touched on the real problem with this code, of course,
>> which is that the XPath is looking for<p>  tags that don't exist.
>>
>> On 2009-10-24 05:48, Stuer Michael 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<erikvv...@...>    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<petteyg...@...>    wrote:
>>>>          
>>      
>>>>> On Fri, Oct 23, 2009 at 4:33 AM, 杨大成<dachen...@...>    wrote:
>>>>>            
>>      
>>>>>> i don't see any js can operate<strong>    ,
>>>>>> how about regex?
>>>>>>              
>>      
>>>>> I repeat: XPath. No need for a regex.
>>>>>            
>>      
>>> ____________________________________________________________________________________
>>> Introducing Branchr
>>> Super Simple Advertising
>>> http://click.lavabit.com/?pub=78&ad=0023&url=aHR0cDovL2JyYW5jaHIuY29t...
>>> ____________________________________________________________________________________
>>>        
> >
>
> ____________________________________________________________________________________
> Introducing Branchr
> Super Simple Advertising
> http://click.lavabit.com/?pub=78&ad=0023&url=aHR0cDovL2JyYW5jaHIuY29tLw==
> ____________________________________________________________________________________
>    


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to obtain a number from the site

by Stuer Michael :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


It works thanks guys :p

now to continue untill my next problem :p

friendly greets

On Oct 27, 2:31 am, cc <carlcl...@...> wrote:

> What you're actually looking for is something a little more like this, I
> think:
>
> var ew = document.evaluate("//strong[2]", document, null, 9, null).singleNodeValue;
>
> if (ew) {
>      ew = ew.innerHTML * 1;
>
>      alert("Number of earthworms is " + ew);
>
> }
>
> This works (or doesn't; I haven't actually tested the whole thing, but
> it should work fine) because you can index nodes found by number
> (starting at 1). Also, I stuck in the check I suggested in the last
> message, to make sure you won't get any null reference errors (the if
> (ew) { and }).
>
> On 2009-10-26 15:41, Stuer Michael wrote:
>
> > so like you guys said i removed the Pcontains thing because there is
> > no<p>
> > and when i first tried he nagged about the return again so i removed
> > it and therefore ended up with :
>
> > var ew=document.evaluate("//strong",document,null,
> > 9,null).singleNodeValue;
>
> > ew=ew.innerHTML*1;
>
> > alert("Number of earthworms is "+ew);
>
> > and when i ran this i finally got output... namely my fishing fever
> > score (wich is a different number in<strong>  a little before the one
> > i need. (actually the one right before it.
>
> > so how can i make him skip the first one and use the second one he
> > finds.
>
> > PS: i allready want to thank all of you for helping me here :p i know
> > i'm not the most experienced scripter but its nice that others help
> > you sometimes :p
>
> > friendly greets
>
> > On 24 okt, 20:46, cc<carlcl...@...>  wrote:
>
> >> The return only works if the chunk of code is within a function. If
> >> you're using a current version of Greasemonkey, it should just work
> >> (because most versions wrap the script in an anonymous function before
> >> executing).
>
> >> Alternatively, reverse the logic of the if statement and put the two
> >> following statements inside the if block, getting rid of the return
> >> statement entirely.
>
> >> Gordon already touched on the real problem with this code, of course,
> >> which is that the XPath is looking for<p>  tags that don't exist.
>
> >> On 2009-10-24 05:48, Stuer Michael 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<erikvv...@...>    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<petteyg...@...>    wrote:
>
> >>>>> On Fri, Oct 23, 2009 at 4:33 AM, 杨大成<dachen...@...>    wrote:
>
> >>>>>> i don't see any js can operate<strong>    ,
> >>>>>> how about regex?
>
> >>>>> I repeat: XPath. No need for a regex.
>
> >>> ____________________________________________________________________________________
> >>> Introducing Branchr
> >>> Super Simple Advertising
> >>>http://click.lavabit.com/?pub=78&ad=0023&url=aHR0cDovL2JyYW5jaHIuY29t...
> >>> ____________________________________________________________________________________
>
> > ____________________________________________________________________________________
> > Introducing Branchr
> > Super Simple Advertising
> >http://click.lavabit.com/?pub=78&ad=0023&url=aHR0cDovL2JyYW5jaHIuY29t...
> > ____________________________________________________________________________________
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@...
To unsubscribe from this group, send email to greasemonkey-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---