我正在尝试使用Selenium :: Remote :: Driverand Browsermob :: Proxy捕获http请求参数。伪代码如下。我无法获得http标头。
任何帮助都将不胜感激。
use Selenium::Remote::Driver;
use Data::Dumper;
my $proxy = Browsermob::Proxy->new(trace => 2);
my $driver = Selenium::Remote::Driver->new(
browser_name => 'firefox',
proxy => $proxy->selenium_proxy(1)
);
$proxy->new_har( payload => {
initialPageRef => '1' }, captureHeaders => 'true',
captureContent => 'true',
captureBinaryContent => 'true');
$driver->get('http://www.google.com/');
print Dumper($proxy->har);
更新:
但是,我只能捕获第一个请求。随后的硒驱动器发出的请求无法捕获。例如,以下代码仅捕获第一个GET请求而不捕获第二个请求。
use Data::Dumper;
use Browsermob::Proxy;
use Selenium::Remote::Driver;
my $proxy = Browsermob::Proxy->new(
server_port => 8080,
);
$proxy->new_har( payload => {
initialPageRef => 'payload is optional' }, captureHeaders => 'true',
captureContent => 'true',
captureBinaryContent => 'true', port => $proxy->port );
my $driver = Selenium::Remote::Driver->new(
browser_name => 'firefox',
proxy => { 'proxyType' => 'manual', 'httpProxy' => '127.0.0.1:'.$proxy->port},
);
$driver->get('http://www.google.com/');
$driver->find_element("//input[\@name='q']")->send_keys("selenium");
$driver->find_element("//button[\@name='btnG']")->click;
print Dumper($proxy->har);
答案 0 :(得分:0)
使用create_new_har
代替new_har
。
$proxy->create_new_har(
payload => {
initialPageRef => 'payload is optional'
},
captureHeaders => 'true',
captureContent => 'true',
captureBinaryContent => 'true'
);