分享

VBA访问网页获取数据

 mastereye 2018-09-06

VBA访问网页获取数据

本文主要介绍VBA访问网页获取数据。

实现效果:将网页中表的数据输出到excel中。




VBA代码:

  1. Sub getResource()
  2. Columns("A:E").ClearContents
  3. Set HTML = CreateObject("htmlfile")
  4. With CreateObject("msxml2.xmlhttp")
  5. URL = "http://data.eastmoney.com/stock/tradedetail.html"
  6. .Open "get", URL, False
  7. .send
  8. HTML.body.innerhtml = StrConv(.responsebody, vbUnicode)
  9. Cells(1, 2) = HTML.body.document.getElementById("notice_Ddl").DefaultValue
  10. Set tr = HTML.all.tags("tr")
  11. j = 1
  12. For r = 0 To tr.Length - 1
  13. If Val(tr(r).Cells(0).innertext) + 1 = j Then
  14. j = j + 1
  15. Cells(j, 1) = tr(r).Cells(0).innertext
  16. Cells(j, 2) = tr(r).Cells(1).innertext
  17. Cells(j, 3) = tr(r).Cells(2).innertext
  18. Cells(j, 4) = tr(r).Cells(6).innertext
  19. Cells(j, 5) = tr(r).Cells(8).innertext
  20. End If
  21. Next
  22. End With
  23. End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多