【问题标题】:How to change guzzle properties from goutte?如何从 goutte 更改 guzzle 属性?
【发布时间】:2014-02-17 09:34:57
【问题描述】:
<?php
require_once '/var/www/goutte.phar';
 use Goutte\Client; 


 $guzzle = parent::getClient(); //You'll want to pull the Guzzle client out of Goutte to inherit its defaults
$guzzle->setDefaultOption('verify', '/path/to/cacert.pem'); //Set the certificate at @mtdowling recommends
$client->setClient($guzzle); //Tell Goutte to use your modified Guzzle client 

$crawler = $client->request('GET', 'https://ocean.ac-guadeloupe.fr/publinet/resultats'); //Proceed as you were
var_dump($crawler);
?>

当我运行上面的代码时,我收到错误“无法访问父级:: 当没有类范围处于活动状态时”。那么如何从 Goutte 访问 Guzzle 属性呢?

【问题讨论】:

    标签: php guzzle goutte


    【解决方案1】:

    示例的开头似乎假设您正在编写 Goutte Client 类的扩展。如果你只是使用类,sn-p 更像是:

    $client = new Client();
    $guzzle = $client->getClient(); //You'll want to pull the Guzzle client out of Goutte to inherit its defaults
    
    $guzzle->setDefaultOption('verify', '/path/to/cacert.pem'); //Set the certificate at @mtdowling recommends
    $client->setClient($guzzle); //Tell Goutte to use your modified Guzzle client 
    
    $crawler = $client->request('GET', 'https://ocean.ac-guadeloupe.fr/publinet/resultats'); //Proceed as you were
    var_dump($crawler);
    

    【讨论】:

    • 我不确定你为什么被否决。我在让 goutte 绕过一些 ssl 自我证书问题时遇到了问题。我按照你说的做了,但是将 ('verify', 'path/to/cert') 更改为 ('verify', false) 并且效果很好。
    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 2016-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-27
    • 2018-07-19
    • 2021-02-09
    相关资源
    最近更新 更多