- Ubuntu 20.04 で確認
起動
起動
docker run \
-d \
--restart=always \
-p 4444:4444 \
selenium/standalone-chrome-debug
応答があることを確認
curl http://localhost:4444/status
操作
sudo apt install -y python3-selenium
qiita.py
from selenium import webdriver
# Chrome のオプションを設定する
options = webdriver.ChromeOptions()
options.add_argument('--headless')
# Selenium Server に接続する
driver = webdriver.Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities=options.to_capabilities(),
options=options,
)
# Selenium 経由でブラウザを操作する
driver.get('https://qiita.com')
# 画面キャプチャ
driver.save_screenshot('screenshot.png')
# urlが出力されればOK
print(driver.current_url)
# ブラウザを終了する
driver.quit()
実行
python3 qiita.py
と表示されれば成功。
画面キャプチャはscreenshot.png
を確認。