I''m sure you could do this, but I''m not familiar with the
block syntax
you have here. This seems to work for me:
agent = WWW::Mechanize.new
form = agent.get(''http://google.com'').form(:name => /\w+/)
form.q = ''test''
page = agent.submit(form)
puts page.links.length
Also I''m sure redefining page in the block syntax like that could lead
to confusion. It looks like you''re trying to grab the links from the
original form page, not the resultant page.
-Mat
On Apr 1, 2009, at 3:47 PM, Frank Gjildberg wrote:
> I got this smalltime social network here with about 200 users. In the
> beginning we didn''t have the "make all users friends of the
admin"
> function that we do now, so I have to manually add these 200 users as
> friend of the admin.
>
> My friend coded this thing in PHP and I ain''t got much insight
into
> its underpinnings (but it''s a mess), so I figured this''d
be a great
> way to learn Mechanize / Nokogiri.
>
> Here''s what I''m trying to do:
>
> 1) Go to http://members.mysite.com
> 2) Log in (the login box is on the same page)
> 3) There''s a select box labeled "Sort by" -- select
"New members"
> 4) List all the users on that page, each user looking like
> http://my.mysite.com/some_user
> 5) Do the same for http://members.mysite.com/?page=2 and all the way
> up to the max (whatever that is)
> 6) Then, for each user, visit its profile page and click on "Add
> friends" (or http://my.mysite.com/<user>/friendship/add_request)
> 7) The system will respond with a blank page saying "Friend request to
> <strong>some_user</strong> is sent"
>
> So far I have:
>
> -
>
> require "rubygems"
> require "mechanize"
>
> agent = WWW::Mechanize.new
>
> agent.get("http://members.mysite.com") do |page|
>
> page.form_with(:name => /login/) do |form|
> form.username = "hahdfgdf"
> form.user_pass = "sdfsdf"
> end.submit
>
> page = agent.click page.link_with(:href => /my.mysite.com/)
>
> end
>
> -
>
> The above script produces this error:
>
> undefined method `username'' for nil:NilClass (NoMethodError), from
> (eval):12:in `form_with''
>
> Even though my login textfield''s name is
"form[username]" and the
> password textfield''s name is "form[user_pass]". Incase
:name =>
> /login/ (should correspond to the form''s ID
"login-form") was nil, I
> also tried :action => "http://mysite.com/login", but without
success.
>
> What am I doing wrong here?
>
> And is the structure etc. of my script looking set to complete the
> rest of the tasks?
>
> Thank you.
>
> Best regards,
> Redd Vinylene
>
> --
> http://www.home.no/reddvinylene
> _______________________________________________
> Mechanize-users mailing list
> Mechanize-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mechanize-users