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

Selenium Chrome Proxy の設定

More than 1 year has passed since last update.

はまったので、メモ書きとして。

Selenium を利用しているときChromeにProxy の設定を行いたい。

Linux OS 側で設定

環境変数として設定する。

    export http_proxy='http://{userid}:{password}@{proxy-server}:{port}'
    export https_proxy='https://{userid}:{password}@{proxy-server}:{port}'

この場合、remoteDriver でlocalhostのSeleniumへの通信もProxyを通ることになる。
ChromeDriverを利用しているだけであれば問題ないが、Script内で他のものに通信する場合もProxyを通る場合が大半。

Chromeのドライバ側で設定

    from selenium.webdriver.chrome.options import Options

    option = Options()
    PROXY = '{proxy-server}:{port}'
    PROXY_AUTH = '{userid}:{password}'
    option.add_argument('--proxy-server=http://%s' % PROXY)
    option.add_argument('--proxy-auth=%s' % PROXY_AUTH)

    driver = webdriver.Chrome(chrome_options=option)

Chrome の起動時にProxyに関するパラメーターを設定することで、Proxy経由での通信とすることができる。

同様にリモートドライバの設定

ChromeDriver利用時の設定と同様に下記の様に設定すれば良いみたい。

    PROXY = '{proxy-server}:{port}'
    PROXY_AUTH = '{userid}:{password}'
    self.driver = webdriver.Remote(
        command_executor='http://{selenium-server}:{port}/wd/hub',
        desired_capabilities={
            'browserName': 'chrome',
            'chromeOptions': {
                'args': [
                    '--start-maximized',
                    '--proxy-server=http://{proxy-server}:{port}',
                    '--proxy-auth={userid}:{password}'
                ]
            }
        })

Why not register and get more from Qiita?
  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
No 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
ユーザーは見つかりませんでした