You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Laravel Goutte提取ea-proclub-overview节点的customCrestBaseUrl属性

实现方法

Goutte依赖的Symfony Crawler组件内置了提取HTML元素属性的attr()方法,你要的customCrestBaseUrl在页面源码中对应属性名为短横线格式的custom-crest-base-url,直接调用该方法即可取值。浏览器控制台中拿到的驼峰格式属性是浏览器自动对自定义属性做的格式转换,不需要在PHP代码中使用驼峰名称。


修改后完整代码

use Goutte\Client;

$client = new Client();
$client->setServerParameter('HTTP_USER_AGENT', 'Mozilla/5.0 (X11; Linux i686; rv:78.0) Gecko/20100101 Firefox/78.0');
$client->setServerParameter('REFERER', 'https://www.ea.com/');

$url = 'https://www.ea.com/en-gb/games/fifa/pro-clubs/ps5-xbsxs/overview?clubId=2552&platform=ps5';
$crawler = $client->request('GET', $url);

// 直接提取目标属性值
$customCrestBaseUrl = $crawler->filter('ea-proclub-overview')->attr('custom-crest-base-url');

// 输出验证结果
dd($customCrestBaseUrl);

多节点遍历写法

如果页面存在多个<ea-proclub-overview>节点,可以使用遍历方式逐个取值:

$crawler->filter('ea-proclub-overview')->each(function ($node) {
    $currentCustomCrestUrl = $node->attr('custom-crest-base-url');
    // 对每个节点的属性值做对应处理
    dd($currentCustomCrestUrl);
});

内容的提问来源于stack exchange,提问作者Zabs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 02:18:03