mechanize & field name for search passed as string

E

Edouard Dantes

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
 
S

Sandor Szücs

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
--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top