Skip to content

Instantly share code, notes, and snippets.

@k5trismegistus
Last active November 11, 2015 16:19
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 k5trismegistus/f5975eb32647d531254e to your computer and use it in GitHub Desktop.
Save k5trismegistus/f5975eb32647d531254e to your computer and use it in GitHub Desktop.
require "nokogiri"
require "uri"
require 'net/http'
require "rss"
require "openssl"
keywords = ['旅順', '203高地']
news_feed_uri = URI.parse("https://news.google.com/news?output=rss&q=" + keywords.join('+'))
http = Net::HTTP.new(news_feed_uri.host, news_feed_uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
rss = RSS::Parser.parse(http.get(news_feed_uri.request_uri).body)
arr = []
rss.channel.items.each do |e|
d = Nokogiri::HTML::parse(e.description)
arr.push({
:title => e.title,
:url => e.link,
:source => d.css('font')[3].text,
:description => d.css('img').attribute('src') ? d.css('font')[5].text : d.css('font')[4].text,
:image_url => d.css('img').attribute('src') ? d.css('img').attribute('src').value[2..-1] : nil ,
})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment