本文介绍了将Poltergeist与代理一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PhantomJS和poltergeist来模拟浏览器,但是我不确定如何指定要在代码中使用的代理:
I'm using PhantomJS and poltergeist to emulate a browser, however I'm not sure how to specify a proxy to use in the code:
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
task :experiment => :environment do
Capybara.run_server = false
Capybara.current_driver = :poltergeist
Capybara.app_host = "http://something.com"
include Capybara::DSL
# set_proxy('12.13.14.15', '4521')
visit('posts')
page.include?('foo')
end
而且,由于某种原因,在使用poltergeist时,我得到了未定义的方法page
,有人可以建议吗?
Also, for some reason, i get undefined method page
when using poltergeist, can anyone advise?
推荐答案
您需要将--proxy
选项传递给PhantomJS,请参见 API文档
You need to pass the --proxy
option to PhantomJS, see the API docs
通过Poltergeist,您可以使用 :phantomjs_options
配置选项来指定用于PhantomJS.
With Poltergeist, you can use the :phantomjs_options
configuration option to specify command line options for PhantomJS.
放在一起:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, phantomjs_options: ["--proxy=12.13.14.15:4521"])
end
这篇关于将Poltergeist与代理一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!