Skip to content

Instantly share code, notes, and snippets.

@SamirTalwar
Last active Oct 3, 2020
Embed
What would you like to do?
A really simple command-line Ruby application, for https://monospacedmonologues.com/2016/02/docker-part-three-running-software/.
FROM ruby
RUN mkdir /app
WORKDIR /app
COPY Gemfile Gemfile
RUN bundle install
COPY google.rb google.rb
RUN chmod +x google.rb
ENTRYPOINT ["./google.rb"]
CMD ["docker"]
source 'https://rubygems.org'
gem 'nokogiri'
#!/usr/bin/env ruby
require 'cgi'
require 'nokogiri'
require 'open-uri'
query = ARGV[0]
html = open("https://google.com/search?q=#{CGI.escape(query)}") { |io|
Nokogiri::HTML(io)
}
results = html.css('.g')
results.each do |result|
header = result.at_css('h3')
puts header.text if header
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment