Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 602 Bytes

README.md

File metadata and controls

24 lines (20 loc) · 602 Bytes

Scraping Instagram Ruby

Let's scrape instagram with Ruby! This is a short sample code to scrape instagram website with instagram user_id. You can get user profile and latest images.

##Code

require 'open-uri'
require 'JSON'

def scrape_instagram(user_id)
  begin
    instagram_source = open("https://www.instagram.com/#{user_id}").read
    content = JSON.parse(instagram_source.split("window._sharedData = ")[1].split(";</script>")[0])
    return content['entry_data']['ProfilePage'][0]['user']
  rescue Exception => e
    return nil
  end
end

##Usage

scrape_instagram("nyanchan22")