Skip to content

Instantly share code, notes, and snippets.

@Kyeongrok
Last active October 23, 2017 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kyeongrok/748de3a0a54812512e8d0bc9f3606426 to your computer and use it in GitHub Desktop.
Save Kyeongrok/748de3a0a54812512e8d0bc9f3606426 to your computer and use it in GitHub Desktop.
' http://cocosoft.kr/442를 참고 했습니다
Private 인터넷익스플로러 As InternetExplorer
Sub main()
    'IE 객체 작성
    Set 인터넷익스플로러 = CreateObject("InternetExplorer.Application")
    검색어 = ENCODEURL("맛집")
    페이지주소 = "https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=" & 검색어

    인터넷익스플로러.Visible = True
    인터넷익스플로러.Navigate2 (페이지주소)
    
    '읽기 완료 대기
    While 인터넷익스플로러.ReadyState <> READYSTATE_COMPLETE Or 인터넷익스플로러.Busy = True
        DoEvents
        Application.Wait (Now + TimeValue("0:00:01"))
    Wend
    Application.Wait (Now + TimeValue("0:00:01"))

    '엑셀 시트에 검색 결과 출력하기
    Row = 1
    For Each element In 인터넷익스플로러.Document.getElementsByClassName("sh_blog_title ")
        Worksheets(1).Cells(Row, 1) = Row
        Worksheets(1).Cells(Row, 2) = element.innerText
        Row = Row + 1
    Next element
    인터넷익스플로러.Quit
    Set 인터넷익스플로러 = Nothing
End Sub


Function ENCODEURL(varText As Variant, Optional blnEncode = True)
    Static objHtmlfile As Object
    If objHtmlfile Is Nothing Then
        Set objHtmlfile = CreateObject("htmlfile")
        With objHtmlfile.parentWindow
            .execScript "function encode(s) {return encodeURIComponent(s)}", "jscript"
        End With
    End If
    If blnEncode Then
        ENCODEURL = objHtmlfile.parentWindow.encode(varText)
    End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment