Created
March 13, 2013 12:12
-
-
Save pnlybubbles/5151536 to your computer and use it in GitHub Desktop.
App.netのMyStreamをスクレイピングで取得してみた。
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
# encoding: utf-8 | |
require 'mechanize' | |
USERNAME = '*' | |
PASSWORD = '*' | |
cookie_path = './tmp/adn_client.cookie.yaml' | |
target = '*' | |
agent = Mechanize.new | |
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
agent.user_agent_alias = 'Mac Safari' | |
agent.cookie_jar.load cookie_path if File.exist? cookie_path | |
uri = URI.parse "https://alpha.app.net" | |
page = agent.get(uri) | |
puts page.title | |
puts page.uri | |
if page.uri.path == '/global/' | |
login_uri = URI.parse "https://account.app.net/login/" | |
page = agent.get(login_uri) | |
form = page.forms[0] | |
form['username'] = USERNAME | |
form['password'] = PASSWORD | |
form.checkbox_with(:name => 'remember_me').check | |
page = form.submit | |
page = agent.get(uri) | |
end | |
puts page.title | |
puts page.uri | |
puts page.search(".post-container").each { |cont| | |
puts "#{cont.search('.username').search('a').inner_text}: #{cont.search('.post-content').inner_text}" unless cont.search('.post-content').empty? | |
} | |
Dir.mkdir('./tmp') unless File.exist?("./tmp") | |
agent.cookie_jar.save_as(cookie_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment