前提・実現したいこと
このGithubを参考にselenium+chrome+pythonの環境を作成しました。localでは正常に動いていますが、proxy設定が必要な環境にて実行を行うと、chromeが「This site can't be reached」と出てしまいます。
Chromeのエラーメッセージ
Try: ・Checking the Connection ・Checking the proxy and the firewall
該当のソースコード
docker-composeにてpython、selenium-hub、node-chrome-debugを立ち上げています。
docker
1selenium-hub: 2 image: selenium/hub 3 container_name: 'selenium-hub' 4 ports: 5 - 4444:4444 6 7chrome: 8 image: selenium/node-chrome-debug 9 container_name: 'chrome' 10 links: 11 - selenium-hub:hub 12 ports: 13 - 5900:5900 14 volumes: 15 - /dev/shm:/dev/shm 16 17python: 18 build: './docker/python-selenium' 19 container_name: 'python' 20 links: 21 - selenium-hub:hub 22 command: 'tail -f /dev/null' 23 working_dir: '/root/script/' 24 volumes: 25 - ./:/root/script/ 26 environment: 27 - 'TZ=Asia/Tokyo' 28 env_file: .env 29
seleniumの操作はpythonにて行っており、以下のコードでproxyを設定して接続しています。
python
1self.driver = webdriver.Remote( 2 command_executor='http://selenium-hub:4444/wd/hub', 3 desired_capabilities={ 4 'browserName': 'chrome', 5 'chromeOptions': { 6 'args': [ 7 '--start-maximized', 8 '--proxy-server=http://{}:{}'.format(self.server, self.port), 9 '--proxy-auth={}:{}'.format(self.userid, self.password) 10 ] 11 } 12 }, 13)
補足情報(FW/ツールのバージョンなど)
接続できるサイトと接続できないサイトがあります(接続できないが圧倒的多数)
あなたの回答
tips
プレビュー