Created
October 3, 2009 18:55
-
-
Save adhusson/200815 to your computer and use it in GitHub Desktop.
This file contains 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
# The purpose is to turn all special characters into ASCII | |
# é -> e | |
# à -> a | |
# etc... | |
require "iconv" | |
require "open-uri" | |
require "rubygems" | |
require "nokogiri" | |
class String | |
# This turns "à" into "`a" | |
def to_ugly_ascii | |
Iconv.iconv("ascii//translit", "utf-8", self)[0] | |
end | |
end | |
doc = Nokogiri::HTML.parse(open("http://unitproj.library.ucla.edu/dlib/lat/display.cfm?ms=uclalat_1429_b3719_G3448&searchType=keyword&k=walburga&w=none&x=title&y=none&z=none&s=1")) | |
text = doc.at "/html/body/div[2]/table/tr[3]/td/table/tr[2]/td/table/tr/td/table/tr[5]/td[2]" | |
html = text.inner_html[76,31] | |
content = text.content[76,31] | |
puts html.to_ugly_ascii | |
puts content.to_ugly_ascii # Returns an error. Why? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment