Help us understand the problem. What is going on with this article?

Selenium php-webdriverでよく使うChromeオプション

php-webdriverを使ってChrome操作する時によく使うオプションメモ

selenium.php
$options = new ChromeOptions();

//ヘッドレスモードを有効にする
$options->addArguments( [ '--headless' ] );

//シークレットモードを有効にする
$options->addArguments( [ '--incognito' ] );

//プロキシサーバーを設定する
$proxy = "xxx.xxx.xxx.xxx:xxxx";
$options->addArguments( [ '--proxy-server='.$proxy] );

//ブラウザデータ保存先を任意指定する
$tmp = "/tmp/chrome/";
$options->addArguments( [ 'user-data-dir='.$tmp]);

//言語を指定する(日本語)
$options->addArguments( [ '--lang=ja-JP' ] );

//UserAgentを指定する
$UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36";
$options->addArguments( [ '--user-agent=' . $UserAgent ] );

//起動時の画面幅を指定する
$width  = 1280;
$height = 1024;
$options->addArguments( [ "window-size={$width},{$height}" ] );

$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability( ChromeOptions::CAPABILITY, $options );
try{
   $driver = RemoteWebDriver::create( $this->selenium_server, $capabilities );
〜〜以下略〜〜

//ヘッドレスモードでファイルをダウンロードする場合の問題を回避
//クラスを継承しておく必要があります extends Facebook\WebDriver\Remote\HttpCommandExecutor
$commands = parent::$commands;
$commands['chromiumSendCommand'] = [ 'method' => 'POST', 'url' => '/session/:sessionId/chromium/send_command' ];
self::$commands = $commands;
//DL場所を指定する
$dl_path = "/tmp"
$driver->execute('chromiumSendCommand', [
   'cmd'    => 'Page.setDownloadBehavior',
   'params' => [ 'behavior' => 'allow', 'downloadPath' => $dl_path ],
]);


参考リンク
php-webdriver

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away