问题描述
我在使用 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 ,但没有成功。我在这里做错了什么?
解决方法
我想这就是您的问题可以解决的方法。 你只是得到各种参数,你需要存储每一个而不是覆盖它们。
domainsearch = [message for message in inbox.item if message.senderemailaddress.endswith("domain.com")
for message in domainsearch
print(message.body)