[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Simple problem w/ WWW::Mechanize

tim.bounceback

4/2/2007 10:59:00 PM

Hi all, I'm fairly new to Ruby, and, as an exercise, I'm writing some
code for webforms. However, I can't seem to get the following code to
work - instead, I get the following error:
wikitesting.rb:8:in `get': undefined method `myform' for
#<WWW::Mechanize::Page:0xb7996738> (NoMethodError)
from wikitesting.rb:10

Probably pretty simple, and I can see it's something wrong with the
way I called the function, however, I've spent some time on it and
can't figure it out. Here's the code:
require 'rubygems'
require 'mechanize'
def get(pagename)
agent = WWW::Mechanize.new
agent.user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1)'
page = agent.get('http://en.wikipedia.org/w/index.php?t... +
pagename + '&action=edit')
myform = page.form('editform')
return page.myform.fields.form('wpTextbox1')
end
text = get('Computer')
pp text

Thanks,

Tim

5 Answers

Aaron Patterson

4/2/2007 11:25:00 PM

0

Hi Tim,

On Tue, Apr 03, 2007 at 08:00:15AM +0900, tim.bounceback@gmail.com wrote:
> Hi all, I'm fairly new to Ruby, and, as an exercise, I'm writing some
> code for webforms. However, I can't seem to get the following code to
> work - instead, I get the following error:
> wikitesting.rb:8:in `get': undefined method `myform' for
> #<WWW::Mechanize::Page:0xb7996738> (NoMethodError)
> from wikitesting.rb:10
>
> Probably pretty simple, and I can see it's something wrong with the
> way I called the function, however, I've spent some time on it and
> can't figure it out. Here's the code:
> require 'rubygems'
> require 'mechanize'
> def get(pagename)
> agent = WWW::Mechanize.new
> agent.user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1)'
> page = agent.get('http://en.wikipedia.org/w/index.php?t... +
> pagename + '&action=edit')
> myform = page.form('editform')

Try replacing this line:

> return page.myform.fields.form('wpTextbox1')

With this:

return myform.wpTextbox1

You've already found the form and stored it in the 'myform' variable.

> end
> text = get('Computer')
> pp text

Also, if you have more questions, be sure to join the mechanize mailing
list:

http://rubyforge.org/mailman/listinfo/mecha...

--
Aaron Patterson
http://tenderlovem...

tim.bounceback

4/2/2007 11:45:00 PM

0

On Apr 2, 7:25 pm, Aaron Patterson <a...@tenderlovemaking.com> wrote:
> Hi Tim,
>
>
>
> On Tue, Apr 03, 2007 at 08:00:15AM +0900, tim.bounceb...@gmail.com wrote:
> > Hi all, I'm fairly new to Ruby, and, as an exercise, I'm writing some
> > code for webforms. However, I can't seem to get the following code to
> > work - instead, I get the following error:
> > wikitesting.rb:8:in `get': undefined method `myform' for
> > #<WWW::Mechanize::Page:0xb7996738> (NoMethodError)
> > from wikitesting.rb:10
>
> > Probably pretty simple, and I can see it's something wrong with the
> > way I called the function, however, I've spent some time on it and
> > can't figure it out. Here's the code:
> > require 'rubygems'
> > require 'mechanize'
> > def get(pagename)
> > agent = WWW::Mechanize.new
> > agent.user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> > 5.1)'
> > page = agent.get('http://en.wikipedia.org/w/index.php?ti...
> > pagename + '&action=edit')
> > myform = page.form('editform')
>
> Try replacing this line:
>
> > return page.myform.fields.form('wpTextbox1')
>
> With this:
>
> return myform.wpTextbox1
>
> You've already found the form and stored it in the 'myform' variable.
>
> > end
> > text = get('Computer')
> > pp text
>
> Also, if you have more questions, be sure to join the mechanize mailing
> list:
>
> http://rubyforge.org/mailman/listinfo/mecha...
>
> --
> Aaron Pattersonhttp://tenderlovem...

Thanks for replying. I still get a similar error, though:
wikitesting.rb:8:in `get': undefined method `wpTextbox1' for
nil:NilClass (NoMethodError)
from wikitesting.rb:10

Any ideas? By the way, I've joined the mailing list, and any future
questions I might have will probably be directed there.

Thanks,

Tim

Aaron Patterson

4/3/2007 5:36:00 AM

0

On Tue, Apr 03, 2007 at 08:50:04AM +0900, tim.bounceback@gmail.com wrote:
> Thanks for replying. I still get a similar error, though:
> wikitesting.rb:8:in `get': undefined method `wpTextbox1' for
> nil:NilClass (NoMethodError)
> from wikitesting.rb:10
>
> Any ideas? By the way, I've joined the mailing list, and any future
> questions I might have will probably be directed there.

It looks like Wikipidia may not like that parameter in the URL. When I
change 'Computer' to 'Main', it seems to work:

require 'rubygems'
require 'mechanize'

def get(pagename)
agent = WWW::Mechanize.new
agent.user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'
page = agent.get('http://en.wikipedia.org/w/index.php?t... +
pagename + '&action=edit')

myform = page.form('editform')
return myform.wpTextbox1
end
text = get('Main')
pp text

--
Aaron Patterson
http://tenderlovem...

tim.bounceback

4/4/2007 8:01:00 PM

0

On Apr 3, 1:36 am, Aaron Patterson <a...@tenderlovemaking.com> wrote:
> On Tue, Apr 03, 2007 at 08:50:04AM +0900, tim.bounceb...@gmail.com wrote:
> > Thanks for replying. I still get a similar error, though:
> > wikitesting.rb:8:in `get': undefined method `wpTextbox1' for
> > nil:NilClass (NoMethodError)
> > from wikitesting.rb:10
>
> > Any ideas? By the way, I've joined the mailing list, and any future
> > questions I might have will probably be directed there.
>
> It looks like Wikipidia may not like that parameter in the URL. When I
> change 'Computer' to 'Main', it seems to work:
>
> require 'rubygems'
> require 'mechanize'
>
> def get(pagename)
> agent = WWW::Mechanize.new
> agent.user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'
> page = agent.get('http://en.wikipedia.org/w/index.php?ti...
> pagename + '&action=edit')
>
> myform = page.form('editform')
> return myform.wpTextbox1
> end
> text = get('Main')
> pp text
>
> --
> Aaron Pattersonhttp://tenderlovem...

OK, thanks, that seems to work!

Tim

djw

8/17/2007 3:23:00 AM

0

On Wed, 15 Aug 2007 05:35:28 -0700, Tab182
<tabernacle2002@hotmail.com> wrote:

>On Aug 14, 10:52 pm, djw <wells.fam...@insightbb.com> wrote:
>> On Tue, 14 Aug 2007 16:22:52 -0400, Harry Hope <riv...@ix.netcom.com>
>> wrote:
>>
>>
>>
>>
>>
>>
>>
>> >From The Associated Press, 8/14/07:
>> >http://www.usatoday.com/money/markets/2007-08-14-wall-stree......
>>
>> >Stocks crunched by credit fears, poor earnings
>>
>> >NEW YORK (AP) -
>>
>> >Stocks pulled back sharply Tuesday on anxiety about the pace of
>> >consumer spending amid a disappointing outlook from Wal-Mart Stores
>> >(WMT) and word that a large money market fund was struggling because
>> >of weeks of volatility.
>>
>> >At the close of trading, the Dow Jones industrial average lost 207.61,
>> >or 1.6%, to 13,028.92.
>>
>> >_______________________________________________
>>
>> >Harry
>>
>> Who cares unless you're a day trader. Volatility is a fact of
>> investing and long term investors should remain unfazed.
>>
>> And this volatility is more the cause of emotions (namely fear and
>> panic) than anything else.- Hide quoted text -
>>
>> - Show quoted text -
>
>Hey djw this is not about the fear of the Monster under the bed,this
>is about the fear of the MONSTER that is just about ready to eat your
>ASS!
>
>Or in this case eat your M O N E Y to the last penny!
>

Actually this is about bad loans to liars. People lying, saying they
earn more than they do, mortgage loan companies not caring whether
they told the truth or not because they're going to flip that mortgage
to some other firm that will turn it into an investment fund.

I've also heard a lot of these people with bad loans are the imbeciles
who watched a show on Discovery channel about flipping properties so
they figured they'd lie about their income to get the loan, then they
got in over their head and couldn't sell the property at the price
needed and couldn't keep up the payments.

I say let 'em go south, those that are going and let the dust settle.
This isn't spreading to other industries and not all those that
they're talking about being at risk will turn out to be dead beats.
Not all 7 million.

>BTW I think the reason Walmart profit forecasts are going down has
>more to do with the fact that their stores are SUCKING (BIGTIME)rather
>than the fact that the economy is slowing?
>
>Heck go into one of their older stores (like more than 2 years old)
>and they look dirty and the carts are all banged up ( I swear 95% of
>the wheels are flapping) with poorly stocked shelves and the lighting
>is simply so bad that on somedays, when you go into one of their
>stores a a cloud passes over, you would swear that the power was
>knocked out and they were on backup power.
>
>Then go on down the road to say the TARGET stores and everyone I have
>gone into to date looked clean and well lit with very good shopping
>carts and nicely stocked shelves and btw with prices (on average)
>about the same as in Walmart!
>
>BTW I forgot to mention the people working in the stores and man talk
>about a contrast as you go into TARGET and you will see that they all
>look like regular people, who, when you ask them a question you get
>help!
>
>Go into Walmart and I swear it looks like a combination of a Nursing
>Home and a Dumping Ground for every Highschool Dropout rejected by the
>local supermarket (because they could not bag or stock shelves)!
>