Created
November 13, 2012 11:15
-
-
Save uu59/4065274 to your computer and use it in GitHub Desktop.
automate to create google alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 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