我现在正在使用一个简单的php crawler叫做Goutte。它使用Guzzle来执行http GET
的请求。我可以执行抓取操作。但是,我试图在filter
内部传递/回显一个变量,但是得到了错误Undefined variable: x
。变量已经定义了。传递变量到filter的正确方法是什么?
$client = new Goutte\Client();
$crawler = $client->request('GET', 'http://github.com/');
$crawler = $client->click($crawler->selectLink('Sign in')->link());
$form = $crawler->selectButton('Sign in')->form();
$x = "hello";
$crawler = $client->submit($form, array('login' => 'xxxxx', 'password' => 'xxxxx'));
$crawler->filter('.flash-error')->each(function ($node) {
echo $x;
print $node->text() . "\n";
});
1条答案
按热度按时间zysjyyx41#
试试看:
如果你不需要在那个函数中修改
&
,你可以删除它。关于在匿名函数中继承父变量的参考。