gpt4 book ai didi

php - 调用未定义的方法 Goutte\Client::setClient()

转载 作者:行者123 更新时间:2023-12-05 02:02:00 24 4
gpt4 key购买 nike

我被这个错误困住了...但客户端已定义。

我的代码是这样的

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 Framework: "6.20.4"


最佳答案

这个答案是关于创建 Goutte 的实例的客户端,一个简单的 PHP Web Scraper


版本 >= 4.0.0

直接在 Goutte Client 实例中传递 HttpClient(guzzle httpclient 或 symfony httpclient)实例。

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.0(即从 0.1.0 到 3.3.1)

use Goutte\Client;
use GuzzleHttp\Client as GuzzleClient;

$goutteClient = new Client();
$guzzleClient = new GuzzleClient(['timeout' => 60]);
$goutteClient->setClient($guzzleClient);

关于php - 调用未定义的方法 Goutte\Client::setClient(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66084721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com