Skip to content

Instantly share code, notes, and snippets.

@chrisallick
Created April 11, 2018 22:59
Show Gist options
  • Save chrisallick/76e1aa3bb4392bb311feeb3a956cad28 to your computer and use it in GitHub Desktop.
Save chrisallick/76e1aa3bb4392bb311feeb3a956cad28 to your computer and use it in GitHub Desktop.
scrape instagram html json
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