screen scraping - How to insert a string to a text field using mechanize in ruby? -
i know simple question i've been stuck hour , can't understand how works.
i need scrape stuff school's library need insert 'ce' text field , click on link text 'clasificación'. output going use work. here code.
require 'rubygems' require 'open-uri' require 'nokogiri' require 'mechanize' url = 'http://biblio02.eld.edu.mx/janium-bin/busqueda_rapida.pl?id=20110720161008#' searchstr = 'ce' agent = mechanize.new page = agent.get(url) searchform = page.form_with(:method => 'post') searchform['buscar'] = searchstr clasificacionlink = page.link_with(:href => "javascript:onclick=set_index_and_submit(\'51\');").click page = agent.submit(searchform,clasificacionlink)
when run it, gives me error
janium.rb:31: undefined method `[]=' nil:nilclass (nomethoderror)
thanks!
mu's answer sounds reasonable. not sure if strictly necessary, might try put braces around searchstr
.
searchform['buscar'] = [searchstr]
Comments
Post a Comment