Created
June 7, 2011 15:52
-
-
Save tejo/1012534 to your computer and use it in GitHub Desktop.
mechanize example with login and saved cookie
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
require 'rubygems' | |
require 'mechanize' | |
require 'mysql' | |
agent = Mechanize.new { |agent| | |
agent.user_agent_alias = 'Mac Safari' | |
} | |
cookie = agent.cookie_jar.load('cookies.yml') rescue false | |
unless cookie | |
page = agent.get('http://www.facebook.com') | |
form = page.forms.first | |
form.email = 'xxxxx' | |
form.pass = 'xxxxxxx' | |
page = agent.submit(form) | |
agent.cookie_jar.save_as('cookies.yml') | |
end | |
page = agent.get('http://www.facebook.com/event.php?eid=199027383467114') | |
count = page.parser.xpath("//h4[@class='uiHeaderTitle']").first.content.match(/\d+/)[0] | |
con = Mysql.new('xxxxx', 'xxxx', 'xxxx', 'xxxxx') | |
rs = con.query("update text_content_translations set content = '#{count}' where id=928") | |
con.close | |
puts "updated with #{count} at: #{Time.now}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment