Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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