class InstaScraper::HTML

Public Instance Methods

data() click to toggle source
# File lib/insta_scraper/html.rb, line 7
def data
  @data ||=
    Hashie::Mash.new(::JSON.parse(shared_data))
                .extend(Hashie::Extensions::DeepFetch)
                .extend(Hashie::Extensions::DeepFind)
end
html() click to toggle source
# File lib/insta_scraper/html.rb, line 3
def html
  @html ||= get_html
end

Protected Instance Methods

serialize_params() click to toggle source
# File lib/insta_scraper/html.rb, line 16
def serialize_params
  return '' if params.empty?

  "?" + params.map {|k, v| "#{k}=#{v}"}.join('&')
end

Private Instance Methods

get_html() click to toggle source
# File lib/insta_scraper/html.rb, line 24
def get_html
  open(url).read
end
line_with_data() click to toggle source
# File lib/insta_scraper/html.rb, line 28
def line_with_data
  html.each_line.detect { |l| l[/sharedData/] }
end
shared_data() click to toggle source
# File lib/insta_scraper/html.rb, line 32
def shared_data
  line_with_data[shared_data_start..shared_data_end]
end
shared_data_end() click to toggle source
# File lib/insta_scraper/html.rb, line 40
def shared_data_end
  line_with_data =~ /\};</
end
shared_data_start() click to toggle source
# File lib/insta_scraper/html.rb, line 36
def shared_data_start
  (line_with_data =~ /sharedData/) + 13
end