본문 바로가기
VBA/엑사남_심화방

[심화방] VBA_심화_100제 #6 [ 스크린샷 ]

by 일등미노왕국 2023. 1. 9.

 

본인처럼 VBA로 스크린샷을 찍길 원했다면 분명 이 글을 읽고 있는 분들은 행복할 것이다. 

왜..???

 

내가 당신들의 뻘짓(?) 시간을 엄청나게 줄여주었기 때문이다.

 

전체 스크린샷 코드는 있어도 

개별 Node에 관한 코드는 찾기가 힘들었을 것이다.

 

그대에게 도움이 되길 원하며 코드를 올린다.

더보기
Sub Take_ScreenShot()
    
    Dim element As Object
    Dim Sel As New Selenium.WebDriver
    Dim Strurl$
    Dim Node As Object
    Dim W&, H&
    
        
        Strurl = "http://www.naver.com"
        Sel.Timeouts.ImplicitWait = 1000
        Sel.AddArgument "--headless --disable--gpu --hide-scrollbars"        '= 헤드리스 모드 / 스크롤 제거
        
        Sel.Start "chrome"                                                   '= 크롬으로 진행
        Sel.Get Strurl
       
       '= 자바스크립트 구문
        W = Sel.ExecuteScript("return document.body.scrollWidth")            '= 화면의 너비
        H = Sel.ExecuteScript("return document.body.scrollHeight")           '= 화면의 높이
        
        Sel.Window.SetSize W, H                                              '= 윈도우 설정
        Sel.TakeScreenshot.SaveAs (ThisWorkbook.Path + "\Screen.png")        '= [ Screen ] 으로 스크린 샷
        
        Set Node = Sel.FindElementByCss(".logo_naver")                       '= 네이버 로고 Element
        Sel.ExecuteScript "arguments[0].scrollIntoView();", Node             '= node를 arguments[0] 에 담아라
        Node.TakeScreenshot.SaveAs (ThisWorkbook.Path + "\Node.png")         '= 요소 스크린 샷
    
        MsgBox "셀레니움 스크린샷을 완료하였습니다."
End Sub

 

 

 

스크린샷.xlsm
0.02MB

댓글