Skip to content

Instantly share code, notes, and snippets.

@vparihar01
Created April 1, 2014 08:44
Show Gist options
  • Save vparihar01/9910345 to your computer and use it in GitHub Desktop.
Save vparihar01/9910345 to your computer and use it in GitHub Desktop.
this is small script will fecth the results of cbse 12th grade results.
require "uri"
require "net/http"
require "nokogiri"
require "logger"
name_final = Array.new
uri = URI.parse("http://resultsarchives.nic.in/cbseresults/cbseresults2004/class12/cbse12.asp")
req = Net::HTTP::Post.new(uri.path, {
'Referer' => "http://resultsarchives.nic.in/cbseresults/cbseresults2004/class12/cbse12.htm",
'User-Agent'=> "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
'Host' => "resultsarchives.nic.in",
'Origin' => "http://resultsarchives.nic.in"
})
(622****..622****).each do |roll_no|
puts "################ #{roll_no}"
req.set_form_data({'regno' => roll_no,'B1' => 'Submit'})
http = Net::HTTP.new(uri.host, uri.port)
http.set_debug_output($stdout)
http.set_debug_output(Logger.new("/tmp/restclient.log"))
http.open_timeout = 40
http.read_timeout = 20
# Request page:
begin
resp = http.request(req)
html_doc = Nokogiri::HTML(resp.body)
puts "#################{html_doc.css('table[2]').css('tr[2]').text}"
name_final << html_doc.css('table[2]').css('tr[2]').text
rescue Exception
puts "Exception requesting the page; returning"
end
puts name_final
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment