php - PHP 无法返回或回显(Goutte)
问题描述
我在使用 Goutte 抓取数据时遇到了一些困难。我的功能如下:
public function getTitle(){
$this->crawler->filter('script')->each(
function ($node) {
print $node->text();
});
}
这实际上会返回我需要的东西,但无论如何它都会返回它,即使我不想在网页上回显或打印。但是当我尝试这样的事情时:
public function getTitle(){
$this->crawler->filter('script')->each(
function ($node) use (&$title) {
$title = $node->text();
});
return $title; // or echo or print
}
它没有返回任何东西。我尝试在爬虫之前定义 $title,但没有成功。我在这里做错了什么?
解决方案
我想这就是你的问题可以解决的方法。你只是得到了各种各样的参数,你需要存储每个参数而不是覆盖它们。
public function getTitle(){
$title =$this->crawler->filter('script')->each(function ($node){
return $node->text();
});
var_dump($title) ;
}
推荐阅读
- python - 我想从 csv 文件中获取每一行并存储打印输出,同时获取 range(10) ValueError: 'nrows' must be an integer >=0
- parallel-processing - MPI_Reduce 和 MPI_Allreduce 的默认实现需要多少跳?
- reactjs - 如何在 React 中添加 activeClass
- python - Firefox 中的 Python Selemium - 单击按钮仅适用于无头模式
- php - 在 Apache2 的 Debian Linux 服务器上安装/启用 PHP LDAP
- javascript - Browserify 窗口函数未定义
- react-native - BottomTabNavigator 未出现在屏幕底部
- android - 直接从 fresco 的管道中获取中心裁剪的图像
- pytorch - pytorch customdataset notimplemented错误
- javascript - Angular,使用基于父组件的短组件选择器