Php 调用未定义的方法Goutte\Client::setClient()
我被这个错误缠住了。。。 但客户机是有定义的 我的代码是这样的Php 调用未定义的方法Goutte\Client::setClient(),php,laravel,web-scraping,guzzle,goutte,Php,Laravel,Web Scraping,Guzzle,Goutte,我被这个错误缠住了。。。 但客户机是有定义的 我的代码是这样的 use Goutte\Client; use Illuminate\Http\Request; use GuzzleHttp\Client as GuzzleClient; class WebScrapingController extends Controller { public function doWebScraping() { $goutteClient = new Client();
use Goutte\Client;
use Illuminate\Http\Request;
use GuzzleHttp\Client as GuzzleClient;
class WebScrapingController extends Controller
{
public function doWebScraping()
{
$goutteClient = new Client();
$guzzleClient = new GuzzleClient(array(
'timeout' => 60,
'verify' => false
));
$goutteClient->setClient($guzzleClient);
$crawler = $goutteClient->request('GET', 'https://duckduckgo.com/html/?q=Laravel');
$crawler->filter('.result__title .result__a')->each(function ($node) {
dump($node->text());
});
}
}
我认为这是一个错误
$goutteClient->setClient($guzzleClient);
goutte:“^4.0”
guzzle:“7.0”
Laravel框架:“6.20.4”
这个答案是关于创建客户端实例的,一个简单的PHP Web刮刀
对于版本>=4.0.0 将HttpClient(guzzle HttpClient、symphony HttpClient)实例直接传递到Goutte客户端实例内部
use Goutte\Client;
use Symfony\Component\HttpClient\HttpClient;// or use GuzzleHttp\Client as GuzzleClient;
$client = new Client(HttpClient::create(['timeout' => 60]));
// or
// $guzzleClient = new GuzzleClient(['timeout' => 60, 'verify' => false]); // pass this to Goutte Client
对于版本4.0中不推荐使用的setClient方法,请将实例直接添加到Goutteoh的构造函数中。问题是,谢谢你@bhucho。用详细的解决方案回答问题,这样可以帮助他人。
use Goutte\Client;
use GuzzleHttp\Client as GuzzleClient;
$goutteClient = new Client();
$guzzleClient = new GuzzleClient(['timeout' => 60]);
$goutteClient->setClient($guzzleClient);