mechanize & field name for search passed as string

Discussion in 'Ruby' started by Edouard Dantes, Jan 21, 2009.

  1. Hi,

    I am writing a method to perform a similar to the below mentionned
    google search but i want it to accept the field's name for the search
    entry as a string.

    In the following example from the Mechanize docs I would expect it to be
    search.send('q') instead of search.q but I get this error

    /scrapingGoogle.rb:14: syntax error, unexpected '=', expecting kEND
    search.send('q') = 'Hello world'.

    Thanks for your comments

    ********************************************************************

    a = WWW::Mechanize.new { |agent|
    agent.user_agent_alias = 'Mac Safari'
    }

    a.get('http://google.com/') do |page|
    search_result = page.form_with:)name => 'f') do |search|
    search.q = 'Hello world'
    end.submit

    search_result.links.each do |link|
    puts link.text
    end
    end
    --
    Posted via http://www.ruby-forum.com/.
     
    Edouard Dantes, Jan 21, 2009
    #1
    1. Advertising

  2. On 21.01.2009, at 05:46, Edouard Dantes wrote:
    >
    > I am writing a method to perform a similar to the below mentionned
    > google search but i want it to accept the field's name for the search
    > entry as a string.
    >
    > In the following example from the Mechanize docs I would expect it =20
    > to be
    > search.send('q') instead of search.q but I get this error


    In the example the method which is called is not q(). It's q=3D(), so
    if you want so send() then use the right method.

    > ./scrapingGoogle.rb:14: syntax error, unexpected '=3D', expecting kEND
    > search.send('q') =3D 'Hello world'.


    search.send('q=3D', 'Hello World') or by symbol
    search.send:)q=3D, 'Hello World')

    regards, Sandor Sz=FCcs
    --
     
    Sandor Szücs, Jan 22, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dee
    Replies:
    9
    Views:
    513
    Joseph Byrns
    Apr 15, 2005
  2. Anand
    Replies:
    2
    Views:
    903
    Anand
    Sep 11, 2003
  3. John Davis
    Replies:
    2
    Views:
    391
    Dave Anderson
    Aug 18, 2003
  4. Pavils Jurjans
    Replies:
    3
    Views:
    188
    Pavils Jurjans
    Mar 18, 2005
  5. Sound
    Replies:
    2
    Views:
    450
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page