Skip to content

Instantly share code, notes, and snippets.

@Ruekompa
Last active August 29, 2015 14:04
Show Gist options
  • Save Ruekompa/ba45f4ad0676459716dd to your computer and use it in GitHub Desktop.
Save Ruekompa/ba45f4ad0676459716dd to your computer and use it in GitHub Desktop.
Nokogiri and Mechanize Introduction
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