Skip to content

Instantly share code, notes, and snippets.

@andreyuhai
Last active October 25, 2019 13:45
Show Gist options
  • Save andreyuhai/3d69252e9cd51aa2549478f22016a80e to your computer and use it in GitHub Desktop.
Save andreyuhai/3d69252e9cd51aa2549478f22016a80e to your computer and use it in GitHub Desktop.
How to use Crawlera proxy with Poltergeist/PhantomJS?

How to use Crawlera proxy with Poltergeist/PhantomJS?

require 'capybara'
require 'capybara/poltergeist'

Capybara.register_driver :poltergeist do |app|
    Capybara::Poltergeist::Driver.new(app, js_errors: false, phantomjs_options: ['--ignore-ssl-errors=true','--load-images=no', '--proxy=proxy.crawlera.com:8010', '--ssl-protocol=any'])
end

session = Capybara::Session.new(:poltergeist)
session.driver.headers = { 'Proxy-Authorization' => "Basic #{Base64.encode64('<API_KEY>:')}" } # Delete <API_KEY> and copy & paste your API KEY.
session.visit 'https://google.com'
session.html

Delete <API_KEY> and copy & paste your own API key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment