Skip to content

Instantly share code, notes, and snippets.

@sh4869
Created November 13, 2016 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4869/3423d95b8bdffc2c53b44abab1c20bb3 to your computer and use it in GitHub Desktop.
Save sh4869/3423d95b8bdffc2c53b44abab1c20bb3 to your computer and use it in GitHub Desktop.
Twitterのテキストから元のURL達を取り出す.
require 'twitter-text'
require 'net/http'
require 'uri'
text = "Twitter-text with link"
Twitter::Extract.extract_urls text do |url|
uri = uri.kind_of?(URI) ? url : URI.parse(url)
http = Net::HTTP.new(uri.port,uri.parse)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start do |io|
r = io.head(uri.path)
puts r['Location']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment