Created
June 16, 2015 17:37
-
-
Save simonszu/dd8d0cb2d74f34b64e58 to your computer and use it in GitHub Desktop.
Fetches everyday's Karotaler from animexx.de
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
#! /usr/bin/env ruby | |
require 'mechanize' | |
# Spezifizieren der Userdaten | |
username = "tatonka" | |
password = "" | |
# Generieren eines neuen Mechanize-Agenten | |
a = Mechanize.new {|agent| | |
agent.user_agent_alias = 'Mac Safari' | |
} | |
# Durchspielen eines regulären Login-Workflows | |
# Mexx aufrufen | |
a.get('http://animexx.onlinewelten.com/') do |page| | |
# Link zur Loginseite raussuchen und öffnen | |
login_page = a.click(page.link_with(:text => /Einloggen/)) | |
# Loginformular ausfuellen und abschicken. Resultat ist die persoenliche Startseite | |
start_page = login_page.form_with(:id => 'login_form') do |f| | |
f.login_username = username | |
f.login_password = password | |
end.click_button | |
# Steckbrieflink raussuchen und oeffnen | |
steckbrief_page = a.click(start_page.link_with(:text => username)) | |
# Aus dem Steckbrief den Link zur Karobank raussuchen und oeffnen | |
karobank_page = a.click(steckbrief_page.link_with(:href => '/items/karo-bank.php')) | |
# Mechanize arbeitet ohne Javascript, daher muss in der Karobank das Abholen nochmal explizit bestaetigt werden | |
karobank_form = karobank_page.form_with(:action => 'karo-bank.php') do |kf| | |
end.click_button | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment