44
43

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 3 years have passed since last update.

【Python】Seleniumでスクリーンショットを撮る

Last updated at Posted at 2019-10-23
  • seleniumで遷移したウェブページのスクショを撮った時のメモ
  • 以下のコードと同ディレクトリ内にimageという名前のディレクトリを作成し実行してください
import os
import sys
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# File Name
FILENAME = os.path.join(os.path.dirname(os.path.abspath(__file__)), "image/screen.png")

# set driver and url
driver = webdriver.Chrome('./chromedriver')
url = 'https://www.rakuten.co.jp/'
driver.get(url)

# get width and height of the page
w = driver.execute_script("return document.body.scrollWidth;")
h = driver.execute_script("return document.body.scrollHeight;")

# set window size
driver.set_window_size(w,h)

# Get Screen Shot
driver.save_screenshot(FILENAME)

# Close Web Browser
driver.quit()

撮られたスクショがこのようにディレクトリimage内に保存されています.

screen.png

GitHubをクローンしてexe.shを実行するのもありです.

44
43
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
44
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?