Last active
September 29, 2016 18:40
-
-
Save vampaynani/1c3493083d785d807e58514ad656da12 to your computer and use it in GitHub Desktop.
Instagram Media Tag Search
This file contains hidden or 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
source "https://rubygems.org" | |
gem 'nokogiri' | |
gem 'sinatra' | |
gem 'headless' | |
gem 'watir' |
This file contains hidden or 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 'nokogiri' | |
require 'open-uri' | |
require 'sinatra' | |
require 'json' | |
get '/tags/:tag/images' do | |
doc = Nokogiri::HTML(open("https://www.instagram.com/explore/tags/#{params['tag']}/")) | |
script = doc.css('script[type="text/javascript"]')[4].to_s | |
json_data = script.gsub('<script type="text/javascript">window._sharedData = ', '').gsub(';</script>', '') | |
raw = JSON.parse json_data | |
nodes = raw["entry_data"]["TagPage"][0]["tag"]["media"]["nodes"] | |
content_type :json | |
nodes.to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment