【发布时间】:2014-04-19 12:30:54
【问题描述】:
我已经问过这个问题几次,但我觉得我没有达到我想要的。这里有几个人提供了帮助,但我仍然有使用数据的问题,因为它的格式不可用。
我希望通过 VBA 将网站上链接的内容放入工作表中
链接位于网页的右上角。
链接是
http://bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet
到目前为止的代码:
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://bmreports.com/servlet/com.logica.neta.bwp_PanBMUTop"
ie.Visible = True
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
ie.Document.getelementbyid("param5").Value = "2014-04-16"
ie.Document.getelementbyid("param6").Value = "43"
ie.Document.getelementbyid("go_button").Click
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).Document.Location
my_title = objShell.Windows(x).Document.Title
If my_url Like "http://bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet" Then
Set ie = objShell.Windows(x)
Exit For
Else
End If
Next
For Each ele In ie.Document.getElementsByTagName("span")
If ele.innerhtml = "Current data in CSV format" Then
DoEvents
ele.Click
'At this point you need to Save the document manually
' or figure out for yourself how to automate this interaction.
End If
Next
If my_url Like "about:blank" Then
Set ie = objShell.Windows(x)
Else
End If
table_html = ie.Document.getElementsByTagName(("Text"))(2).innerhtml
html_lines = Split(table_html, Chr(10), -1, vbTextCompare)
Worksheets("Sheet1").Activate
Range("A1").Select
For x = 0 To UBound(html_lines)
ActiveCell = html_lines(x)
ActiveCell.Offset(1, 0).Select
Next
【问题讨论】:
-
你为什么不链接到其他问题并解释为什么你觉得你没有实现它?到目前为止你做了什么?
-
你的问题不是很清楚;这可能就是为什么你没有得到你想要的答案。您希望 VBA 代码究竟做什么?
-
如果您打开链接,在页面内有一个链接,称为当前数据,格式为 csv。我想通过 VBA 自动将其内容放入电子表格中。
-
到目前为止,这里有人帮助我将表格从实际网页复制到电子表格中。但我很快意识到这不是下降的路线