Class: Spidy::Connector::Lightpanda
- Inherits:
-
Object
- Object
- Spidy::Connector::Lightpanda
- Includes:
- StaticAccessor
- Defined in:
- lib/spidy/connector/lightpanda.rb
Overview
Lightpanda connector for JavaScript-rendered pages via CDP Using Ferrum for direct CDP connection
Defined Under Namespace
Classes: LightpandaPage
Constant Summary collapse
- DEFAULT_HOST =
'127.0.0.1'.freeze
- DEFAULT_PORT =
9222
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #call(url) {|page| ... } ⇒ Object
-
#initialize(user_agent:, host: nil, port: nil) ⇒ Lightpanda
constructor
A new instance of Lightpanda.
- #refresh! ⇒ Object
Constructor Details
#initialize(user_agent:, host: nil, port: nil) ⇒ Lightpanda
Returns a new instance of Lightpanda.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/spidy/connector/lightpanda.rb', line 13 def initialize(user_agent:, host: nil, port: nil) begin require 'ferrum' rescue LoadError raise 'Ferrum gem is required. Please install with: gem install ferrum' end @user_agent = user_agent @host = host || ENV['LIGHTPANDA_HOST'] || DEFAULT_HOST @port = port || ENV['LIGHTPANDA_PORT'] || DEFAULT_PORT end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/spidy/connector/lightpanda.rb', line 8 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/spidy/connector/lightpanda.rb', line 8 def port @port end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
8 9 10 |
# File 'lib/spidy/connector/lightpanda.rb', line 8 def user_agent @user_agent end |
Instance Method Details
#call(url) {|page| ... } ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/spidy/connector/lightpanda.rb', line 25 def call(url) fail 'url is not specified' if url.blank? # Clean the URL by removing any whitespace or newlines clean_url = url.to_s.strip puts "Processing URL: #{clean_url}" if ENV['DEBUG'] # Create a page-like object similar to Mechanize page = fetch_with_ferrum(clean_url) # Apply yielder to the page yield(page) end |
#refresh! ⇒ Object
40 41 42 |
# File 'lib/spidy/connector/lightpanda.rb', line 40 def refresh! # No special refresh actions needed for Lightpanda end |