我正在使用"fabpot/goutte": "^3.2"
和PHP 7.3.5
。
我正在尝试使用goutte从网站获取数据:
<?php
require_once 'vendor/autoload.php';
use Goutte\Client;
$client = new Client();
$subCrawler = $client->request('GET', 'https://www.forexfactory.com/calendar.php?month=nov.2019');
$currArray = array();
$impactArray = array();
$reportArray = array();
// currency
$subCrawler->filter('td.calendar__cell.calendar__currency.currency')->each(function ($node) use (&$currArray) {
$currency = $node->text();
array_push($currArray, trim($currency));
});
// impact
$subCrawler->filter(' td.calendar__cell.calendar__impact.impact.calendar__impact.calendar__impact > div.calendar__impact-icon.calendar__impact-icon > span')->each(function ($node) use (&$impactArray) {
$impact = $node->text();
array_push($impactArray, trim($impact));
});
//report
$subCrawler->filter('td.calendar__cell.calendar__event.event > div > span')->each(function ($node) use (&$reportArray) {
$report = $node->text();
array_push($reportArray, trim($report));
});
$multi = array();
foreach ($currArray as $key => $v) {
$multi[] = [$currArray[$key], $impactArray[$key], $reportArray[$key]];
}
$json_data = json_encode($multi);
file_put_contents('data/data.json', $json_data);
如您所见,我只为我的影响数组获取370
值,而不是376
值,我无法将其添加到我的最终数组-$multi[]
-中,因为顺序是不对。
在数组的不同大小下查找
有人建议我在做什么错吗?
感谢您的答复!