ruby on rails - Using the Mechanize gem with the Nokogirl gem? -
i'm trying scrape website requires authentication element on page id of #celltotal
.
right now, using mechanize have logged page want access, using basic nokogiri functions like:
@selector = page.css("#celltotal").text
gives me error:
undefined method `css' #<mechanize::page:0x61234f8>
here have far:
agent = mechanize.new agent.get("example.com") agent.page.forms[0]["username_field"] = "username" agent.page.forms[0]["password_field"] = "password" agent.page.forms[0].submit @selector = agent.page.css("#celltotal").text
how can select element on page?
you can use page.parser
gain access underlying nokogiri
object.
http://mechanize.rubyforge.org/mechanize/page.html#method-i-parser
require 'mechanize' agent = mechanize.new agent.get("http://stackoverflow.com/questions/23064821/using-the-mechanize-gem-with-the-nokogirl-gem/") agent.page.parser.class # => nokogiri::html::document agent.page.parser.css("#answer-23065003 .user-details a").text # => "akatakritos"
Comments
Post a Comment