Skip to content

Instantly share code, notes, and snippets.

@aileron
Created April 4, 2012 12:30
Show Gist options
  • Save aileron/2300796 to your computer and use it in GitHub Desktop.
Save aileron/2300796 to your computer and use it in GitHub Desktop.
短縮URLとか展開する
def extract_tiny_url(url)
url = URI.parse(url) if url.is_a?String
TCPSocket.open(url.host, url.port) do|s|
s.write("GET #{url.path} HTTP/1.1")
s.write("\nHost: #{url.host}")
s.write("\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:11.0) Gecko/20100101 Firefox/11.0")
s.write("\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
s.write("\nAccept-Language: ja-JP-mac,ja;q=0.8,en-US;q=0.5,en;q=0.3")
s.write("\n\n")
text = (s.readlines.join('').scan /URL=([a-z:\/\.\_0-9]*)/).flatten.first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment