NeoVe NeoVe - 1 year ago 88
Ruby Question

How to scrape website with search button

I have this website: codigos if You look at it, it has a selection field at left, and a go button at right, I need to scrape some of the items on left.

But, how can I tell to mechanize in ruby how to access that selection field and then make the search and scrape it?

I've seen examples with login forms but I don't know if it can really suit this case though.

Answer Source

The <select> tag is contained within a <form> tag, so you need to locate the form and then you can set the option by passing the name of the select list and specifying the appropriate option:

require 'mechanize'

mechanize =
page = mechanize.get('')

form = page.forms.first
form["wlw-select_key:{actionForm.opcion}"] = "Aduana"

result_page = form.submit
result_page.uri #=>;jsessionid=2hGwYfzD76WKGfFbXJvmS2yq4K19VnZycJfH8hJMTzRFhln4pTy2!1794372623!-1405983655!8080!-1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download