Skip to content

Instantly share code, notes, and snippets.

@tondol
Created December 18, 2015 18:31
Show Gist options
  • Save tondol/c857b9eac48837e4da39 to your computer and use it in GitHub Desktop.
Save tondol/c857b9eac48837e4da39 to your computer and use it in GitHub Desktop.
Instagramをいい感じに
require 'pp'
require 'watir-webdriver'
directory = File.dirname($0)
config = YAML.load_file(directory + "/config.yml")
USERNAME = ARGV.shift
def instagram(username, password)
browser = Watir::Browser.new :phantomjs
browser.goto("https://www.instagram.com/")
browser.text_field(:name, "username").wait_until_present
browser.text_field(:name, "password").wait_until_present
browser.text_field(:name, "username").value = username
browser.text_field(:name, "password").value = password
browser.button(:text, /ログイン/).click
browser.button(:text, /ログイン/).wait_while_present
yield browser
browser.close
end
instagram(config["username"], config["password"]) {|insta|
insta.goto("https://www.instagram.com/#{USERNAME}/")
insta.div(:class, 'l68').div(:class, 'm68').wait_until_present
shared_data = insta.execute_script("return _sharedData")
nodes = shared_data["entry_data"]["ProfilePage"][0]["user"]["media"]["nodes"]
next_href = $1 if insta.html =~ /max_id=(\d+)/
pp nodes, next_href
}
@tondol
Copy link
Author

tondol commented Feb 4, 2016

古くなったから後でアップデートする

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment