Php 可以用Goutte解析JSON吗?

Php 可以用Goutte解析JSON吗?,php,json,html-parsing,goutte,Php,Json,Html Parsing,Goutte,我正在抓取网站,到目前为止,用Goutte解析HTML没有问题。但是我需要从网站上检索JSON,由于cookie管理,我不想用file\u get\u contents() 我可以使用纯卷曲,但在这种情况下,我只想使用痛风,不想使用任何其他库 那么,有没有什么方法可以通过Goutte只解析文本,或者我真的必须用好的老方法来解析 /* Sample Code */ $client = new Client(); $crawler = $client->request('foo'); $cra

我正在抓取网站,到目前为止,用Goutte解析HTML没有问题。但是我需要从网站上检索JSON,由于cookie管理,我不想用
file\u get\u contents()

我可以使用纯卷曲,但在这种情况下,我只想使用痛风,不想使用任何其他库

那么,有没有什么方法可以通过Goutte只解析文本,或者我真的必须用好的老方法来解析

/* Sample Code */
$client = new Client();
$crawler = $client->request('foo');
$crawler = $crawler->filter('bar'); // of course not working

谢谢。

在Goutte图书馆内进行了深入搜索后,我找到了一种方法,我想与大家分享。因为Goutte是一个非常强大的库,但是有如此复杂的文档

解析JSON通过(Goutte>Guzzle)

只需获取所需的输出页面并将json存储到数组中

使用Cookies解析JSON通过(Goutte+Guzzle)-用于身份验证

向站点的一个页面(主页看起来更好)发送请求以获取cookie,然后使用这些cookie进行身份验证


我希望有帮助。因为我几乎花了3天的时间来理解Gouttle及其组件

mithataydogmus的解决方案对我不起作用。我创建了一个新类“BetterClient”:

用法:

$client = new BetterClient();
$request = $client->request('GET', $url);
$data = $client->getGuzzleResponse()->json();

经过几个小时的搜索,我发现了这一点,只需执行以下操作:

$client = new Client(); // Goutte Client
$crawler = $client->request("GET", "http://foo.bar");

$jsonData = $crawler->text();

我还可以通过以下方式获得JSON:

$client->getResponse()->getContent()->getContents()

我试图使用您的第一个方法,但是我得到了一个错误调用,未定义的方法Guzzle http\Message\Request::send()Guzzle没有方法send和json。在我查看api之后,这是解决问题的代码
$response=$client->getClient()->send($Request)$client=newclient()$guzzleClient=$client->getClient()$headers=array('Authorization'=>'Bearer'.$accessToken)$request=$guzzleClient->createRequest('GET',$linkedInUrl,array('headers'=>$headers))$流=$guzzleClient->send($request);
$client = new BetterClient();
$request = $client->request('GET', $url);
$data = $client->getGuzzleResponse()->json();
$client = new Client(); // Goutte Client
$crawler = $client->request("GET", "http://foo.bar");

$jsonData = $crawler->text();
$client->getResponse()->getContent()->getContents()