我希望在点击此链接后获取新闻内容。
所以,我尝试使用我的代码:
$crawler = $this->client->request('GET', 'http://giaitri.vnexpress.net');
$news = $crawler->filter('#news_home > li');
$link = null;
$news = $crawler->filter('#news_home > li')->each(function($node) {
$link = $node->filter('.txt_link');
$child_news = $this->client->click($link->link());
print_r($child_news->filter('#left_calculator')->text());
if(!empty($child_news->filter('#left_calculator'))) {
return [
'title' => $link->text(),
'link' => $link->link()->getUri(),
'thumbnail' => $node->filter('.txt_link img')->attr('src'),
'description' => trim($node->filter('.news_lead')->text()),
'content' => trim($child_news->filter('#left_calculator')->text()),
];
}
});
print_r($child_news->filter('#left_calculator')->text())
有值。
但是在阵列中:
'content' => trim($child_news->filter('#left_calculator')->text()),
显示如下错误:
The current node list is empty.