Dockerfile
# https://github.com/symfony/panther#docker-integration
FROM php:latest
RUN apt-get update && apt-get install -y libzip-dev zlib1g-dev chromium && docker-php-ext-install zip
ENV PANTHER_NO_SANDBOX 1
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composerdocker-compose.yml
version: "3"
services:
crawler:
build: .
working_dir: /usr/src
volumes:
- .:/usr/src
command: /bin/sh -c "/usr/local/bin/composer install && php index.php"composer.json
{
"require": {
"symfony/panther": "^0.6.0"
}
}index.php
<?php
// https://github.com/symfony/panther#basic-usage
require __DIR__.'/vendor/autoload.php'; // Composer's autoloader
$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();
$client->takeScreenshot('screen.png'); // Yeah, screenshot!所有文件都在同一个位置。我运行docker-compose build && docker-compose up并得到以下错误:crawler_1 | Fatal error: Uncaught RuntimeException: Could not start chrome (or it crashed) after 30 seconds. in /usr/src/vendor/symfony/panther/src/ProcessManager/WebServerReadinessProbeTrait.php:51
这与https://github.com/symfony/panther/issues/200类似,但是在我的例子中,我不使用黑豹进行测试,而是只使用它进行测试,而且我真的不知道如何解决这个问题。我想我的问题可能与无效的码头/码头组合文件有关。
发布于 2019-12-12 21:41:19
我也犯了同样的错误。我的解决方案是安装解压缩,如自述文件中所述:
警告:在*nix系统上,必须安装unzip命令,否则您将遇到类似于RuntimeException: sh: 1: exec: RuntimeException权限被拒绝(或chromedriver_linux64: not )的错误。其根本原因是ZipArchive不保留ZipArchive可执行权限。
最后,重新安装黑豹库。
https://stackoverflow.com/questions/58942792
复制相似问题