Skip to content

Instantly share code, notes, and snippets.

@petervojtek petervojtek/zrsr.rb
Created Apr 28, 2015

Embed
What would you like to do?
Zivnostnensky register z Ruby (zrsr.sk)
# kod nizsie vyhlada zivnostnikov ktori maju ako obec uvedene Malinovo
require 'uri'
require 'net/http'
uri = URI('http://www.zrsr.sk/zr_om.aspx')
res = Net::HTTP.get_response(uri)
require 'nokogiri'
doc = Nokogiri::HTML.parse res.body
cookie = res.to_hash['set-cookie'][0].split(';')[0]
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({'txtFirma' => '',
'txtUlica' => '',
'txtCislo' => '',
'listOU' => '',
"txtObec" => "malinovo",
'cmdVyhladat' => 'Vyhľadať',
'__EVENTTARGET' => '',
'__EVENTARGUMENT' => '',
'__VIEWSTATE' => doc.css('input')[0].attributes['value'].value,
'__VIEWSTATEGENERATOR' => doc.css('input')[1].attributes['value'].value,
'__EVENTVALIDATION' => doc.css('input')[2].attributes['value'].value
})
request["Cookie"] = cookie
request["Referer"] = 'http://www.zrsr.sk/zr_om.aspx'
request["Content-Type"] = 'application/x-www-form-urlencoded'
response = http.request(request)
uri = URI('http://www.zrsr.sk/zr_browse.aspx')
request = Net::HTTP::Get.new(uri.request_uri)
request["Cookie"] = cookie
request["Referer"] = 'http://www.zrsr.sk/zr_om.aspx'
request["Content-Type"] = 'application/x-www-form-urlencoded'
response = http.request(request)
puts response.body # vysledky vyhladavanie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.