[英]PHP can't return or echo (Goutte)
我在使用 Goutte 抓取數據時遇到了一些困難。 我有 function 喜歡:
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) ;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.