Sha256: 108f7fc34a9c3319cb454c6ed1a63419002ac97a2633b457176638bbff262de7

Contents?: true

Size: 806 Bytes

Versions: 4

Compression:

Stored size: 806 Bytes

Contents

module InstaScraper
  class HTML
    def html
      @html ||= get_html
    end

    def data
      @data ||=
        Hashie::Mash.new(::JSON.parse(shared_data))
                    .extend(Hashie::Extensions::DeepFetch)
                    .extend(Hashie::Extensions::DeepFind)
    end

    protected

    def serialize_params
      return '' if params.empty?

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

    private

    def get_html
      open(url).read
    end

    def line_with_data
      html.each_line.detect { |l| l[/sharedData/] }
    end

    def shared_data
      line_with_data[shared_data_start..shared_data_end]
    end

    def shared_data_start
      (line_with_data =~ /sharedData/) + 13
    end

    def shared_data_end
      line_with_data =~ /\};</
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
insta_scraper-0.8.0 lib/insta_scraper/html.rb
insta_scraper-0.7.0 lib/insta_scraper/html.rb
insta_scraper-0.6.1 lib/insta_scraper/html.rb
insta_scraper-0.6.0 lib/insta_scraper/html.rb