Excel VBA, Web Crolling, 주가 가져오기 v3
Sub stock_v3()
'v1 today stock price
'v2 timer
'v3 exchange rate
Dim ie As InternetExplorer
Dim strURL As String
Dim i As Integer
Dim start_time As Single
Dim end_time As Single
start_time = Timer
Range(Range("D3"), Range("D3").End(xlDown)).ClearContents
For i = 3 To Range("C1000").End(xlUp).Row
Set ie = CreateObject("InternetExplorer.application")
strURL = "https://finance.naver.com/item/coinfo.nhn?code=" & Range("C" & i)
ie.Navigate strURL
ie.Visible = False
Do While (ie.ReadyState <> READYSTATE_COMPLETE Or ie.Busy = True)
DoEvents
Loop
Application.Wait (Now + TimeValue("00:00:01")) '1초 대기
Range("D" & i).Value = ie.document.getElementById("nowVal_td_0").innerText 'today stock price
ie.Quit
Set ie = Nothing
Next i
Set ie = CreateObject("InternetExplorer.application")
strURL = "https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=%ED%99%98%EC%9C%A8"
ie.Navigate strURL
ie.Visible = False
Do While (ie.ReadyState <> READYSTATE_COMPLETE Or ie.Busy = True)
DoEvents
Loop
Range("A2").Value = ie.document.getElementsByTagName("strong")(16).innerText
ie.Quit
Set ie = Nothing
end_time = Timer
MsgBox Round(end_time - start_time) & "seconds elapsed."
'v1 today stock price
'v2 timer
'v3 exchange rate
Dim ie As InternetExplorer
Dim strURL As String
Dim i As Integer
Dim start_time As Single
Dim end_time As Single
start_time = Timer
Range(Range("D3"), Range("D3").End(xlDown)).ClearContents
For i = 3 To Range("C1000").End(xlUp).Row
Set ie = CreateObject("InternetExplorer.application")
strURL = "https://finance.naver.com/item/coinfo.nhn?code=" & Range("C" & i)
ie.Navigate strURL
ie.Visible = False
Do While (ie.ReadyState <> READYSTATE_COMPLETE Or ie.Busy = True)
DoEvents
Loop
Application.Wait (Now + TimeValue("00:00:01")) '1초 대기
Range("D" & i).Value = ie.document.getElementById("nowVal_td_0").innerText 'today stock price
ie.Quit
Set ie = Nothing
Next i
Set ie = CreateObject("InternetExplorer.application")
strURL = "https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=%ED%99%98%EC%9C%A8"
ie.Navigate strURL
ie.Visible = False
Do While (ie.ReadyState <> READYSTATE_COMPLETE Or ie.Busy = True)
DoEvents
Loop
Range("A2").Value = ie.document.getElementsByTagName("strong")(16).innerText
ie.Quit
Set ie = Nothing
end_time = Timer
MsgBox Round(end_time - start_time) & "seconds elapsed."
End Sub
댓글
댓글 쓰기