Ice*_*mux 3 php api goutte laravel-5.1
我正在尝试使用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;
}
Run Code Online (Sandbox Code Playgroud)
我得到的只是一个空数组.
哈哈!我做的!看看这个!
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();
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1523 次 |
| 最近记录: |