【发布时间】:2016-10-24 12:43:49
【问题描述】:
我正在尝试通过在 Excel 中使用 VBA 代码从 http://www.dsebd.org/displayCompany.php?name=LINDEBD 获取数据。
试图从此链接获取以下数据
已发行证券总数 部门 公司名称
正在尝试,
Sub GetData()
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://www.dsebd.org/displayCompany.php?name=LINDEBD"
With IE
.Visible = True
.navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
End With
Application.Wait (Now() + TimeValue("00:00:016")) ' For internal page refresh or loading
Set Results = IE.document.getElementsByTagName("table")
For Each itm In Results
If itm.classname = "lgn" Then
dd = itm.getAttribute("href")
Exit For
End If
Next
' if you wnat to click the link
itm.Click
' otherwise
'Range("a1").Value = dd
MsgBox dd
End Sub
是否可以从本网站收集数据
【问题讨论】:
-
那里的代码出了什么问题?
-
运行时错误 404,需要对象。我觉得这里有问题, If itm.classname = "lgn" Then dd = itm.getAttribute("href")
-
注释掉
itm.Click会停止错误,但dd最后是NULL,因为代码找不到任何classname或lgn