#selenium부분캡쳐
#selenium필요한부분스크린샷
selenium을 이용하여 화면을 캡쳐하는데,
특정 위치만 캡처하고 싶을 때 아래와 같이 하면됩니다.
구글링을 하니 별 쓸때 없는 예제가 많아서 ...
전체 소스는 아닙니다.
element1 = browser.find_element_by_class_name('캡처할 위치의 메인 Html의 class명')
element_png = element1.screenshot_as_png
with open("test1.png", "wb") as file:
file.write(element_png)
쓸때 없이, Image 패키지를 이용해서
element = browser.find_element_by_class_name('캡처할 위치의 메인 Html의 class명')
image_location = element.location
image_size = element.size
im = Image.open(BytesIO(png))
left = image_location['x']
top = image_location['y']
right = image_location['x'] + image_size['width']
bottom = image_location['y'] + image_size['height']
im = im.crop((left, top, right, bottom))
im.save('test2.png')
이렇게 할 필요가 없습니다.
이상입니다.
'프로그래밍' 카테고리의 다른 글
postgresql 세팅 (1) | 2022.11.09 |
---|---|
파이참 단축키 모음 - PyCharm 단축키 (0) | 2021.01.25 |
라즈베리파이 3 세팅 (0) | 2019.12.24 |
파이썬 PEF 8 변수명 규칙 (0) | 2019.12.22 |
파이썬 Selenium 패키지 (0) | 2019.12.09 |
파이썬 selenium find_element_by_class_name 에서 공백 오류 (0) | 2019.11.28 |