I tried to take a screenshot automatically using Selenium, but no matter how large the size was specified, it was cut off at the screen size and I had a hard time getting the bottom of the scroll, so this is a memorandum.
chromedriver (matching the version of chrome you are using) selenium python
It was OK if I added headless in options.
screenshot.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
if __name__ == "__main__":
#Settings required for inseparable screenshots
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
#Specify a wider size
driver.set_window_size(1400, 2000)
#Specifying the capture destination
driver.get(r'https://ja.wikipedia.org/wiki/Qiita')
#Capture execution. Specify the save file.
driver.save_screenshot('screenshot.png')
driver.close()
If you add headless in options, Chrome will not start. If you don't attach it, the screenshot will be cut off probably because when Chrome starts up, the height and width will be slightly modified according to the window width. .. .. When. Maybe so.
Recommended Posts