【发布时间】:2014-11-12 16:59:54
【问题描述】:
问题:
我想从多个 Internet Explorer 网站检索特定值(Prev Close)并将它们自动复制到多个单元格(C 列)。我知道如何将价值从单个 Internet Explorer 网站检索到单个单元格。但我不知道如何从多个网站检索并将它们复制到多个单元格。
我的电脑信息:
1.window 8.1
2.excel 2013
3.ie 11
我的 Excel 参考资料
微软对象库:是的
Microsoft Internet Controls:是的
Microsoft Form 2.0 对象库:是
Microsoft Script Control 1.0:是的
网址:
http://finance.yahoo.com/q?s=hpq&type=2button&fr=uh3_finance_web_gs_ctrl1&uhb=uhb2
下面是我的 VBA 代码:
Private Sub CommandButton1_Click()
Dim ie As Object
Dim Doc As HTMLDocument
Dim prevClose As String
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = 0
ie.navigate "http://finance.yahoo.com/q;_ylt=AsqtxVZ0vjCPfBnINCrCWlXJgfME?uhb=uhb2&fr=uh3_finance_vert_gs_ctrl1_e&type=2button&s=" & Range("b2").Value
Do
DoEvents
Loop Until ie.readyState = 4
Set Doc = ie.document
prevClose = Trim(Doc.getElementById("table1").getElementsByTagName("td")(0).innerText)
Range("c2").Value = prevClose
End Sub
【问题讨论】:
-
您需要使用多个标签,还是只是从多个网站获取?
-
@ptwales 多个网站都可以
标签: vba internet-explorer web-scraping pull yahoo-finance