Skip to content

Instantly share code, notes, and snippets.

@uu59
Created November 13, 2012 11:15
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 uu59/4065274 to your computer and use it in GitHub Desktop.
Save uu59/4065274 to your computer and use it in GitHub Desktop.
automate to create google alert
# -- coding: utf-8
require "rubygems"
require "grill"
Grill.implant <<-G
source :rubygems
gem "masque"
gem "nokogiri"
G
m = Masque.new(:driver => :webkit)
m.run do
visit "http://www.google.co.jp/alerts/manage"
within('#gaia_loginform') do
fill_in "Email", :with => "your@gmail.com"
fill_in "Passwd", :with => "PASSWORD"
end
find('#signIn').click
visit "http://www.google.co.jp/alerts"
keyword = ARGV.first
{
"q" => keyword,
"e" => "feed",
"t" => 1, # news:1, all:7
"f" => 1, # unknown
"l" => 1, # all or recent
}.each_pair do |k,v|
find("input[name=#{k}]").set v
end
find('#create_alert').click
wait_until(5) do
current_url["/alerts/manage"]
end
doc = Nokogiri::HTML.parse(page.body)
a = doc.at_xpath(%Q'//a[contains(@href, "#{URI.encode_www_form_component keyword}")]/ancestor::tr//a[contains(@href, "/alerts/feeds/")]')
puts a.attributes["href"].to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment