반응형
스크린샷 찍기
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
# chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
driver.get("<https://point-nine.com/layout/res/home.php?go=main>")
# 스크린 샷 저장
driver.get_screenshot_as_file('data/test.png')
스크롤 하며 스크린샷 찍기
- 스크린 샷 찍기 → 스크롤 내리기 → 몇 초기다리기 → 다시 스크린샷 찍기
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
driver.get("<https://www.google.com/search?q=%EC%A0%9C%EB%8B%88+%EB%AA%B8%EB%A7%A4&tbm=isch&ved=2ahUKEwiu2_y6go35AhXJEKYKHdFAB7wQ2-cCegQIABAA&oq=%EC%A0%9C%EB%8B%88+%EB%AA%B8%EB%A7%A4&gs_lcp=CgNpbWcQAzoICAAQgAQQsQM6CAgAELEDEIMBOgsIABCABBCxAxCDAToFCAAQgAQ6BAgAEAM6BAgAEBg6BggAEB4QBVCiBFjWCWCQC2gAcAB4AIABwAGIAZIIkgEDMC43mAEAoAEBqgELZ3dzLXdpei1pbWfAAQE&sclient=img&ei=F97aYu7zMsmhmAXRgZ3gCw&bih=834&biw=1512>")
driver.get_screenshot_as_file('data/test0.png')
for i in range(1,5) :
scroll_index = i * 1000
# 1000 2000 3000 4000
# 스크롤 내리기
# 더 내리고 싶을 때는 1000 + (내리고 싶은 스크롤 정도) 를 입력해야 한다.
driver.execute_script("window.scrollTo(0," + str(scroll_index) + ")")
# 스크린 샷 저장
driver.get_screenshot_as_file('data/test' + str(scroll_index) + '.png')
# 이미지 로딩 기다리기
time.sleep(1)
반응형