Skip to content

Instantly share code, notes, and snippets.

Created January 29, 2011 00:18
Show Gist options
  • Save anonymous/801301 to your computer and use it in GitHub Desktop.
Save anonymous/801301 to your computer and use it in GitHub Desktop.
require 'mechanize'
require 'nokogiri'
require 'sinatra'
get '/:psuid' do
find_name params[:psuid]
end
def find_name(psuid)
result = ''
a = Mechanize.new
a.get('http://psu.edu/ph') do |page|
search_result = page.form_with(:name => 'search') do |search|
search.uid = psuid
end.submit
doc = Nokogiri::HTML(search_result.content)
word = doc.css('html body form table tr td b')[0].text
name = word[21,word.length]
new_word = ""
name.split(" ").each do |n|
n.downcase!.capitalize!
new_word << n+" "
end
result = new_word
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment