5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモ: selenium/standalone-chrome-debug

Posted at
  • 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

https://qiita.com/

と表示されれば成功。

画面キャプチャはscreenshot.pngを確認。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?