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

ARP/RARP full simulation program

server.c #include "stdio.h" #include "stdlib.h" #include "string.h" #include "sys/types.h" #include "sys/socket.h" #include "arpa/inet.h" #include "netinet/in.h" #define SA struct sockaddr struct IPmac { char ip[100]; char mac[100]; }; int main() { int sockfd,len,i; struct sockaddr_in servaddr; char buff[30],temp[30],ip[30],mac[30];

Configure opendns in ubuntu 12.04

Today i have changed my dns server name to opendns. which is alternative to default dns and it provide more secure, faster browsing experience. What is opendns? OpenDNS is the leading provider of Internet security and DNS services Industry leading malware and botnet protection Award winning Web filtering Faster, reliable, more secure DNS Ultra-reliable, globally distributed cloud network Simple, Smart, Easy How to configure opendns in ubuntu 12.04: open terminal and type sudo nano /etc/resolv.conf enter your password and change these lines   nameserver 208.67.222.222  nameserver 208.67.220.220 to use google public dns use 8.8.8.8, 8.8.4.4 instead of 208.67.222.222, 208.67.220.220 simple isn't..! now see your facebook load faster than before. opendns comes with parental control, so never worry about unwanted websites, and your childrens are safe now. to check your dns changed successfully goto welcome.opendns.com

Given a string, reverse only vowels in it; leaving rest of the string as it is

/* Given a string, reverse only vowels in it; leaving rest of the string as it is. Input : abcdef Output : ebcdaf */ import java.io.*; import java.util.*; public class VowelReverse { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); String vowels = ""; String ans = ""; int arr[] = new int[str.length()]; for(int i=0;i<str.length();i++) { if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u') { vowels+=str.charAt(i); arr[i]=1; } } String revVowels = new StringBuffer(vowels).reverse().toString(); int j=0; for(int i=0;i<str.length();i++) { if(arr[i]!=1) { ans+=str.charAt(i); } else { ans+=revVowels.charAt(j); j++; } } System.out.println(ans); } }