ruby - Pick the correct form from Mechanize results via CSS selector -


so use mechanize fetch list of forms page. form identification can vary websites, need more stable, such selector.

is there way can use simple css selector pick right form list of forms provided mechanize?

yes. page object returned mechanize nokogiri document can use of nokogiri's methods find node in dom.

search , at generic methods, , both take either css or xpath selectors. at equivalent search('some selector').first. use 2 vast majority of times need find node. there css , xpath selector-type specific , at equivalents of at_css , at_xpath.

consider code:

require 'mechanize'  agent = mechanize.new page = agent.get('http://www.example.net') page.class # => mechanize::page page.at('title').class # => nokogiri::xml::element page.at('title').text # => "example domain" 

this example gets page's <title> can interpolate how particular form dom you're working this.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -