# Mechanize & field name for search passed as string

**URL:** <https://www.ruby-forum.com/t/mechanize-field-name-for-search-passed-as-string/158260>\
**Category:** Ruby\
**Created:** [January 21, 2009, 5:48am UTC](https://www.ruby-forum.com/t/mechanize-field-name-for-search-passed-as-string/158260 "2009-01-21T05:48:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![edouard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c57346/32.png) [@edouard](https://www.ruby-forum.com/u/edouard)\
**Post date:** [January 21, 2009, 5:48am UTC](https://www.ruby-forum.com/t/mechanize-field-name-for-search-passed-as-string/158260/1 "2009-01-21T05:48:35Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![edouard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c57346/32.png) [@edouard](https://www.ruby-forum.com/u/edouard)\
**Post date:** [January 22, 2009, 11:15am UTC](https://www.ruby-forum.com/t/mechanize-field-name-for-search-passed-as-string/158260/2 "2009-01-22T11:15:10Z")

</div>

On 21.01.2009, at 05:46, Edouard D. 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  
> 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=(), so  
if you want so send() then use the right method.

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

search.send(‘q=’, ‘Hello World’) or by symbol  
search.send(:q=, ‘Hello World’)

regards, Sandor  
Szücs
