PHP return 使用 Goutte 抓取时的数组
PHP return array when scraping with Goutte
我正在尝试 return 一组带有 goutte 的项目,我可以将它们打印出来,但我希望它们在一个数组中,例如 API。这是示例代码。我正在使用 Laravel 5.1.
public function index()
{
$posts = array();
$client = new Client();
$crawler = $client->request('GET', 'http://www.icetimux.com');
$crawler->filter('h2 > a')->each(function ($node) use ($posts){
// print $node->text(); //this prints them, needs to return as an array :(
array_push($posts, $node->text());
});
return $posts;
}
我得到的只是一个空数组。
哈哈!我做到了!看看吧!
public function index()
{
$client = new Client();
$crawler = $client->request('GET', 'http://www.icetimux.com');
return $result = $crawler->filter('h2 > a')->each(function ($node){
return $posts[] = $node->text();
});
}
我正在尝试 return 一组带有 goutte 的项目,我可以将它们打印出来,但我希望它们在一个数组中,例如 API。这是示例代码。我正在使用 Laravel 5.1.
public function index()
{
$posts = array();
$client = new Client();
$crawler = $client->request('GET', 'http://www.icetimux.com');
$crawler->filter('h2 > a')->each(function ($node) use ($posts){
// print $node->text(); //this prints them, needs to return as an array :(
array_push($posts, $node->text());
});
return $posts;
}
我得到的只是一个空数组。
哈哈!我做到了!看看吧!
public function index()
{
$client = new Client();
$crawler = $client->request('GET', 'http://www.icetimux.com');
return $result = $crawler->filter('h2 > a')->each(function ($node){
return $posts[] = $node->text();
});
}