Sub LoopGetStockData()
Dim StartTime As Variant
Dim UsedTime As Variant
StartTime = VBA.Timer Cells.ClearContents
For y = 2017 To 2007 Step -1
For s = 4 To 1 Step -1
GetStockData "600000", y, s
Next s
Next UsedTime = VBA.Timer - StartTime
Debug.Print "UsedTime :" & Format(UsedTime, "#0.0000 Seconds")
'MsgBox "UsedTime :" & Format(UsedTime, "#0.0000 Seconds") End Sub
Sub GetStockData(ByVal StockNo As String, ByVal YearNo As String, ByVal SeasonNo As String) URL = "http://xxx.com/trade/lsjysj_" & StockNo & ".html?year=" & YearNo & "&season=" & SeasonNo
'发送请求
With CreateObject("WinHttp.WinHttpRequest.5.1")
' With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.setRequestHeader "Content-Type", "text/html"
.Send
WebText = .responsetext
'Debug.Print WebText
'Range("A1").Value = WebText
End With Dim OneTable As Object
Dim OneTh As Object
Dim OneTr As Object
Dim tHead As Object
Dim tBody As Object
Dim r As Long, c As Long
With CreateObject("htmlfile")
.write WebText
Set OneTable = .getElementsByTagName("table")(3)
r = Cells(Cells.Rows.Count, 1).End(xlUp).Row + 1
If r = 2 Then r = 1 Set tHead = OneTable.FirstChild
Set tr = tHead.FirstChild
c = 0
If r = 1 Then
For Each OneTh In tr.ChildNodes
c = c + 1
Cells(r, c).Value = OneTh.innerText
Next OneTh
End If
Set tBody = tHead.NextSibling
For Each OneTr In tBody.ChildNodes
r = r + 1
c = 0 For Each td In OneTr.ChildNodes
c = c + 1
Cells(r, c).Value = td.innerText
Next td
Next OneTr End With Set OneTable = Nothing
Set OneTh = Nothing
Set OneTr = Nothing
Set tHead = Nothing
Set tBody = Nothing End Sub

  

20180226xlVbaGetStockData的更多相关文章

随机推荐

  1. Lottie的json动画

    我们的设计如是说: Lottie的json动画,优缺点有 优点: 1.开发成本低,动画的还原度高.设计师导出 json 文件后,交付开发.原本要1天甚至更久的动画实现,现在只要不到一小时甚至更少时间了 ...

  2. Oracle使用——Oracle表空间处理

    创建表空间 查看表空间信息(名称.大小)  select t1.name tablespace_name ,t2.name file_local ,t2.bytes / (1024 * 1024) f ...

  3. 简单明了的掌握diff命令? 参考: http://www.ruanyifeng.com/blog/2012/08/how_to_read_diff.html

    diff是比较两个 文本文件, 或目录,(中名字相同的文件) diff 是按行来比较的, 只要两个对应的行, 不完全一致, 就报告为不同, 否则就视为相同. (一行中任意一点的不同...) 检查时, ...

  4. 再谈fedora 23中的flash的安装

    安装下载, flash插件的地址是 https://get.adobe.com/flashplayer/ ls 的显示, 记住两个很常用的选项: 指定 "假设的屏幕的宽度" , - ...

  5. MySQL 命令操作数据表

    MySQL 命令操作数据表 1.查看表信息 desc hs_user_credit_info; 2.新增表字段 alter table hs_credit_order add search_relat ...

  6. reshape2

    require(reshape2)x = data.frame(subject = c("John", "Mary"),                 tim ...

  7. c# 之系统环境安装

    在重装系统后,对一些原有软件进行了卸载,不知道是什么原因总是提示vs2015 需安装IE10,但是又碰到ie10的一些插件不适合此系统.网上介绍的vs修复没有任何作用 最后找到方法是:重装系统,然后不 ...

  8. 一文读懂 深度强化学习算法 A3C (Actor-Critic Algorithm)

    一文读懂 深度强化学习算法 A3C (Actor-Critic Algorithm) 2017-12-25  16:29:19   对于 A3C 算法感觉自己总是一知半解,现将其梳理一下,记录在此,也 ...

  9. WebPack填坑笔记

    loader使用时不需要用require引入,在使用plugins(插件)才需要使用require引入 压缩js代码会导致热更新失效 所以开发环境先不要进行压缩 给css加前缀的 postcss-lo ...

  10. 【Hadoop 分布式部署 十 一: NameNode HA 自动故障转移】

    问题描述:    上一篇就是NameNode 的HA 部署完成,但是存在问题,问题是如果 主NameNode的节点宕机了,还是需要人工去使用命令来切换NameNode的Acitve 这样很不方便,所以 ...