Created
April 1, 2014 08:44
-
-
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.
This file contains hidden or 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 "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