我正在使用带有 Laravel 框架的 Symfony Panther。我在使用这个时遇到了错误
未知错误:无法为用户数据目录创建临时目录 {"exception":"[object] (Facebook\WebDriver\Exception\UnknownErrorException(code: 0):
我已经为 Windows 7.4.2 安装了 XAMPP。
PHP:7.4.2,阿帕奇:2.4.41
作曲家.json
"require": {
"php": "^7.1.3",
"fabpot/goutte": "^3.2",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "~6.0",
"laravel/framework": "5.7.*",
"laravel/tinker": "^1.0",
"symfony/css-selector": "^4.4",
"symfony/http-client": "^4.4",
"symfony/panther": "^0.7.0"
}
Laravel 控制器类
namespace App\Http\Controllers;
include (base_path() .'/vendor/autoload.php');
use Illuminate\Http\Request;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\HttpClient\HttpClient;
class PageController extends Controller
{
public function myFunction(Request $request)
{
$client = \Symfony\Component\Panther\Client::createChromeClient();
$client->request('GET', 'https://api-platform.com'); // Yes, this website is 100% written in JavaScript
$client->clickLink('Support');
// Wait for an element to be rendered
$crawler = $client->waitFor('.support');
echo $crawler->filter('.support')->text();
}
}
[2020-02-27 16:12:21] local.ERROR: unknown error: cannot create temp dir for user data dir {"exception":"[object] (Facebook\WebDriver\Exception\UnknownErrorException(code: 0):未知错误:无法在 D:\WWW\PHP\myproject\vendor\php-webdriver\webdriver\lib\Exception\WebDriverException.php:139 为用户数据目录创建临时目录