我有一个带有这个头的php 7+文件
<?php
require __DIR__.'/vendor/autoload.php';
use Facebook\WebDriver\Interactions\WebDriverActions;
use Facebook\WebDriver\WebDriverBy;
try {
$arguments = [
"--no-sandbox",
"--disable-gpu",
"--headless"
];
$options = [
'download.default_directory' => '/tmp',
'window-size'=>'1024,768',
'profile.managed_default_content_settings.cookies'=>1,
];
$client = \Symfony\Component\Panther\Client::createChromeClient('',$arguments,$options);
//... read every link in front page
//...for to click in each link
// pass the page where the url is
$actioWebObj= new WebDriverActions($pantherCrawlerObj->WebDriver());
// pass the url to click
$actionWebObj->movetoElement($remoteWebElementObj);
//... write in a csv file html data of the visited page
此代码功能正常,并且我在 csv 中拥有我需要的所有数据服务器页面。现在,我尝试将此代码传递给 laravel 8,我将代码放在 App/Classes/ReadWebClass.php 中
<?php
namespace App\Classes;
use Symfony\Component\Panther\Client;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\Interactions\WebDriverActions;
class ReadWebClass{
/**
* read all the web and save to the ddbb
* @return void
*/
static function readWeb(){
//
try{
$arguments = [
"--no-sandbox",
"--disable-gpu",
"--headless"
];
$options = [
'download.default_directory' => '/tmp',
'window-size'=>'1024,768',
'profile.managed_default_content_settings.cookies'=>1,
];
$client = Client::createChromeClient('',$arguments,$options);
//... read every link in front page
//for to click in each link
// with a dd I have the same list of link with the simple php code
$actioWebObj= new WebDriverActions($pantherCrawlerObj->WebDriver()); //(<-throw error)
$actionWebObj->movetoElement($remoteWebElementObj);
在 laravel 中,来自 cath 的 $th 向我显示:“调用未定义的方法 Symfony\Component\Panther\DomCrawler\Crawler::WebDriver()” 在 CVCode 的调试器中,$pantherCrawlerObj 是 Symfony\Component\Panther\DomCrawler 的对象\Crawler 类并具有正确的数据。我已经使用作曲家安装了所有东西,它发送给我 ok 。