VBA 根據股票代碼查詢價格

未實現定時刷新
Sub 抓取股票價格()
On Error Resume Next
Set regx = CreateObject("vbscript.regexp") '
regx.Global = True
regx.Pattern = "\[""(.*)"",""(.*)"",(\d+),(.*),(.*),(\d{8}).*\]" '


arr_stock = Range(Cells(2, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1)) '股票代碼數組
string_stock = Join(Application.Transpose(arr_stock), ",") '股票代碼數組分成字符串


https = "http://q.jrjimg.cn/?q=cn|s&i="

https = https & string_stock & "&c=code,name,np,pl,time,stp&o=pl,d&n=realHqxny_concept_9000&_=1507340273905"
Set ie = CreateObject("internetexplorer.application")
ie.navigate https


Do Until ie.readystate = 4
    DoEvents
Loop

With ie.document
   
    string_body = .body.innerText '返回的代碼
    
    Set mh = regx.Execute(string_body) '應用正則
    
    For Each m In mh
        i = i + 1
       
        Cells(i + 1, 2) = m.submatches(1) '公司名稱
        Cells(i + 1, 3) = m.submatches(3) '價格
        Cells(i + 1, 4) = m.submatches(4) '漲跌幅
        Cells(i + 1, 5) = m.submatches(5) '日期
    Next
    
 
ie.Quit
End With

Set ie = Nothing
Set regx = Nothing
End Sub


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章