Sha256: 2d1be9770d1e74b9e45cbe7c15486e52dd481007ed1142820aea9c93ea623062

Contents?: true

Size: 621 Bytes

Versions: 1

Compression:

Stored size: 621 Bytes

Contents

class JohnStamos::ExtractionHelper
  def self.embedded_page_json(page_content)
    seed_json_identifier = 'P.start.start'

    embedded_script = page_content.search('script').select do |script|
      script['src'].nil? && script.content.include?(seed_json_identifier)
    end

    embedded_script_content = embedded_script.last.content
    # This regex used in the range snatches the parameter Pinterest uses to
    # start their app... This parameter happens to be a JSON representation of
    # the page.
    raw_json = embedded_script_content[/#{seed_json_identifier}\((.*)\);/m, 1]

    JSON.parse(raw_json)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
john_stamos-0.0.3 lib/john_stamos/extraction_helper.rb