Last active
August 29, 2015 14:04
-
-
Save Ruekompa/ba45f4ad0676459716dd to your computer and use it in GitHub Desktop.
Nokogiri and Mechanize Introduction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'open-uri' | |
require 'mechanize' | |
require 'nokogiri' | |
class Mechanize::Form | |
def postback target, argument | |
self['__EVENTTARGET'], self['__EVENTARGUMENT'] = target, argument | |
submit | |
end | |
end | |
agent = Mechanize.new | |
page = agent.get 'https://secure.pascocountyfl.net/bccpapa/Opal/SinkHoleReport.aspx' | |
form = page.form_with(:action => 'SinkHoleReport.aspx') | |
form.field_with(:name => "ctl00$ContentPlaceHolder2$txtFromDate").value = '04/25/20014' | |
form.field_with(:name => "ctl00$ContentPlaceHolder2$txtTodate").value = '07/25/2014' | |
form.field_with(:name => "ctl00$ContentPlaceHolder2$ddlStatus").value = "3" | |
form.radiobutton_with(:name => "ctl00$ContentPlaceHolder2$Sink").value = "1" | |
form.radiobutton_with(:name => "ctl00$ContentPlaceHolder2$Type").checked = "rdoBusiness" | |
form.radiobutton_with(:name => "ctl00$ContentPlaceHolder2$SearchType").checked = "rdoStarts" | |
page = form.submit(form.button_with(:value=>'Search')) | |
document = Nokogiri::HTML(page.content) | |
document.css("#ctl00_ContentPlaceHolder2_gvwBuildingPermits tr")[1..-2].each do |tr| | |
puts tr.css('td').map{ |td| | |
td.text.gsub(/[$,](?=\d)/, '').gsub(/\302\240|\s/, ' ').strip | |
}.join(" | ") | |
end | |
#=> 828424 | ADVANCED PIER TECHNOLOGY, LLC | 1626140160000000090 | COMPLETE | GRND SETTLE REPAI | 8406 | BASALISK CT | NEW PORT RICHEY | 34 | 06-05-2014 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment