未实现定时刷新 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
原文地址:http://13834900127.blog.51cto.com/3664326/1970619