Web scraping 使用Behat/Mink时加载GouttClient时出错
我正在尝试使用Behat/Mink加载网站 我已使用Composer进行安装,这是我的Composer.json:Web scraping 使用Behat/Mink时加载GouttClient时出错,web-scraping,scraper,mink,goutte,Web Scraping,Scraper,Mink,Goutte,我正在尝试使用Behat/Mink加载网站 我已使用Composer进行安装,这是我的Composer.json: { "require": { "behat/mink": "*", "behat/mink-goutte-driver": "*", "behat/mink-selenium-driver": "*", "behat/mink-selenium2-driver": "*", "behat/mi
{
"require": {
"behat/mink": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-sahi-driver": "*",
"behat/mink-zombie-driver": "*"
}
}
为了进行安装,我运行了以下命令:
$ curl http://getcomposer.org/installer | php
$ php composer.phar install
安装顺利,没有任何错误消息
这是我的index.php文件:
require 'vendor/autoload.php';
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\GoutteDriver,
Behat\Mink\Driver\Goutte\Client as GoutteClient,
Behat\Mink\Driver\SahiDriver;
$startUrl = 'www.example.com';
// init Mink and register sessions
$mink = new Mink(array(
'goutte1' => new Session(new GoutteDriver(GoutteClient($startUrl))),
'goutte2' => new Session(new GoutteDriver(GoutteClient($startUrl))),
'javascript' => new Session(new SahiDriver('firefox')),
'custom' => new Session(new MyCustomDriver($startUrl))
));
我尝试使用以下命令运行它:
$ php index.php
但是,我收到以下错误消息:
PHP致命错误:在中调用未定义的函数GoutteClient()
第14行的index.php
指的是这一行:
'goutte1' => new Session(new GoutteDriver(GoutteClient($startUrl))),
安装是使用以下文档完成的:
该示例是按照文档进行的:
有没有关于我做错了什么的建议?您在GoutClient之前忘记了“new”关键字。你应该写:
$mink=新的mink(数组)(
“goutte1”=>新会话(新GoutteDriver(新GoutteClient($startUrl)),
“goutte2”=>新会话(新GoutteDriver(新GoutteClient($startUrl)),
“javascript”=>新会话(新SahiDriver(“firefox”),
“自定义”=>新会话(新的MyCustomDriver($startUrl))
));
顺便说一句:你根本不需要初始化GouteClient,GouteDriver应该可以正常工作
以下是Mink standalone的一个工作示例:要运行behat,您不需要运行从命令行调用behat的php文件。考虑阅读所有的文档,因为这感觉就像你停止阅读,走下另一条路。您可以使用bin/behat命令启动它。behat.yml文件用于加载goutte和其他要使用的驱动程序。您不必直接用php代码加载它。让框架为您做到这一点。