Created
April 11, 2018 22:59
-
-
Save chrisallick/76e1aa3bb4392bb311feeb3a956cad28 to your computer and use it in GitHub Desktop.
scrape instagram html json
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 'open-uri' | |
require 'json' | |
require 'nokogiri' | |
doc = Nokogiri::HTML(open("https://www.instagram.com/chrisallick/")) | |
data = "" | |
doc.css('script').each do |script| | |
if script.content[0,30].include? "window._sharedData" | |
data = script.content[21...-1] | |
data = JSON.parse(data) | |
end | |
end | |
data["entry_data"]["ProfilePage"][0]["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"].each do |node| | |
puts node["node"]["display_url"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment