Skip to content

Instantly share code, notes, and snippets.

@twtw
Created April 18, 2012 05:16
Show Gist options
  • Save twtw/2411237 to your computer and use it in GitHub Desktop.
Save twtw/2411237 to your computer and use it in GitHub Desktop.
parse TANet roaming members domain and name
# get count number from html file
require 'hpricot'
doc=Hpricot(open('online.txt'))
>> doc.search("tr").size
=> 61
>> doc.search("tr")[0].at('td').innerText
=> "online people : 50"
msg = doc.search("tr")[0].at('td').innerText
count = msg.split(':')[1].strip
#!/bin/sh
# fetch ePassport 150-ETP online page
# query by snmp
snmpwalk -Os -c public -v 1 1.2.3.4
# get html
curl -d"user=myuser&passwd=mypass" http://1.2.3.4/servlets/utility.login -D cook.txt
curl -b cook.txt http://1.2.3.4/servlets/admin.online > online.txt
# parse TANet roaming members domain and name
require 'hpricot'
require 'open-uri'
#doc=Hpricot(open('roam.html'))
doc=Hpricot(open('http://roamingcenter.tanet.edu.tw/select_all.php'))
tds=doc.search("a")
#tds.each_with_index{|k,i| puts k if i%2 == 1}
hash = {}
tds.each_with_index do |a,i|
next if i%2 == 0
name = a.innerText
url = a.attributes['href']
arr=url.split('/')
arr[2] =~ /^\w+\d?+\.(.*)/
hash[$1] = name
end
puts hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment