Skip to main content

இணைய சுரண்டல் (web scrapping) ரூபி ஸ்கிரிப்ட்டில்

நேற்று சென்ணை பல்கலைகழக தேர்வு முடிவுகள் வெளியானது. ஒவ்வொரு resultஐயும் தனித்தனியாக பார்க்க ரொம்ப நேரமாகும். எல்லாருடைய resultஐயும் ஒரே பக்கத்தில் பார்க்க இந்த script உதவியது. என் நண்பர் ராஜ்குமார் அண்ணா பல்கலைகழக தேர்வு முடிவுகளை எடுக்க இந்த scriptஐ எழுதினார். நான் இதை சிறிது மாற்றியுள்ளேன் (சென்னை பல்கலைக்கழகத்திற்காக). இதைக்கொண்டு html மற்றும் txt fileஆக output எடுக்க முடியும்.

அதற்கு முன் hpricot மற்றும் open-uri என்ற இரு gemகள் தேவை

$sudo gem install hpricot open-uri

கொடுத்து நிறுவிகொள்ளவும்

# Fetch my class students exam result from University site
# Progamme name scrabing_exam_results.rb
# Author : Rajkumar.S
# moded by: Manimaran G
# version : 0.01
# License: GNU GPL 3

require 'rubygems'
require 'open-uri'
require 'hpricot'

url = "http://schools9.com/mad0702.aspx?htno="
# exam_no is a range
exam_no = "s900488".."s900517"

exam_no.each do |each_number|
doc=Hpricot(open(url+each_number))
data=doc.search('table')
# write a file as html format easily view all results in one page
File.open("result.html","a") {|f| f.puts(data)}
# find the inside content of table tag
x=doc.search('table').inner_html
# it is remove the html tags
a=x.gsub(/<\/?[^>]*>/,"")
# spearate an array where \n is placed
b=a.split.join("\n")
puts b+"\n"+"======================="

File.open("result.txt","a") { |f| f.puts(b+"\n\n"+"=================")}

end


எதாவது சந்தேகம் இருந்தால் தெரிவிக்கவும்.

நன்றி: http://upcomer.wordpress.com/

Comments

  1. பயனுள்ள பதிவு ! நன்றி நண்பரே !

    ReplyDelete
    Replies
    1. நன்றி நண்பா.
      தவறாக நிணைக்க வேண்டாம். உங்களுக்கு எந்த வகையில் பயனளித்தது என்று கூற முடியுமா?

      Delete
  2. rubyயின் range பயன்பாடு கலக்கலாக இருக்கிறது. இதில் gems என்பது லைப்ரரியைக் குறிக்கிறதா?

    ReplyDelete

Post a Comment

Popular posts from this blog

விண்டோஸை விட லினக்ஸ் சிறந்தது: பத்து காரணங்கள்

லினக்ஸ் பயன்படுத்த கடினம், விண்டோஸே சிறந்தது என கருதுபவர்களுக்காக 1. வைரஸ் அபாயம் கிடையாது: ஆம். பொரும்பாலான வைரஸ் நிரல்கள் விண்டோஸிற்காக எழுதப்படுபவை. லினக்ஸால் win32  நிரல்களை  செயல்படுத்த முடியாது. எனவே வைரஸ் வரும் என்ற கவலை வேண்டாம். 2. திற-மூலமென்பொருள் - விண்டோஸ் போல் அல்லாமல் லினக்ஸ் ஆனது திற-மூல-இயங்குதளம்(open-source).  எனவே நம்முடைய தேவைக்கு ஏற்ப நாம் இதனை மாற்றவே, பிறருக்கு அளிக்கவோ முழு சுதந்திரம் உண்டு.

சிடி/டிவிடிகளை காப்பி செய்யாதீர்கள்.

நாம் பொதுவாக டிவிடி படங்களை நம்முடைய கணினிகளில் டிவிடி டிரைவ்களில் போட்டு பார்ப்பது பழக்கம். நாம் நண்பர்களிடம் இருந்தோ அல்லது வேறுயாரிடமாவது இருந்தோ படங்களை வாங்கி உடனே பார்த்துவிட்டு தருவதற்கு முடியவில்லை என்றால் நாம் படங்களை காப்பி செய்து அதனை நம் கணினீயில் சேமிப்போம். அவ்வாறு சேமித்த படங்களை டிவிடி டிரைவில் போட்டு பார்ப்பது போன்றே சௌகரியமாக பார்ப்பது என்பது இயலாது. ஒவ்வொரு fileஐயும் நாம் விடியோ ப்ளேயரில் திறக்க வேண்டும். அதில் பலவிதமான fileகள் இருக்கும். நாம் ஒவ்வொன்றாக திறந்து நாம் பார்க்க வேண்டிய அந்த படத்தை பார்ப்பதற்குள் நேரம் ஆகிவிடும். சில fileகள் ஒழுங்காக காப்பி ஆகியிருக்காது. சில டிவிடிக்கள் காப்பி ஆக மறுக்கும்.

need your response

It has been a long time... my rest hours are reduced i only sleep for 5 to 6 hours a day.. so i can't post frequently.. sorry friends.. my university is a good place to refine myself. yes..! thoughts about my programming computers are refined there.. i always wanted share my experience.. but i feared of thinking that it will helpful for you or not.. most of us don't like to hear stories of others. so i stopped blogging and of course having less time.. i have earned some good friends there... who are interested in open-source technology.. very few of us only know the linux platform.. this semester mini project also in open softwares like mysql, postgrey sql i will start blogging my experience if you are interested.. regards, Mani G