20180226xlVbaGetStockData
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的更多相关文章
随机推荐
- Spring 学习——Spring框架结构、概念
maven项目结构 记忆:在一个项目中,project下一层级时src,也就是源文件,所有需要进行编译的文件都是在这个目录下,其实也就是这一个目录,然后向下扩展.在src目录下,存在main文件夹,里 ...
- gerrit的使用笔记
1.clone的时候一定要同时选择上clone with commit-msg hook和ssh,这样才能使用change id,同时使用ssh push到remote. 2.如果是使用了clone ...
- cumtoj 一起来选课
一起来选课 题目地址:http://192.168.173.163/JudgeOnline/problem.php?cid=1019&pid=7 题目 明泽私立大学有n门课程提供给大一的同学来 ...
- CF161D Distance in Tree(点分治)
点分治是一种处理树的优秀暴力 这是一道板子题 #include <cstdio> #include <cstring> #include <algorithm> u ...
- twitter ads_campaign management
下载链接
- 在Mac OSX下安装Microsoft Calibri字体
参考: Where can I find default Microsoft fonts Calibri, Cambria? 在Mac OSX下安装Microsoft Calibri字体 1.下载: ...
- 【Django】【Shell】
django-admin startproject guest python manage.py startapp sign python manage.py runserver 127.0.0.1: ...
- 【BZOJ】3144: [Hnoi2013]切糕
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3144 MDZZ,不知道为什么被卡常数了/TAT(特判才过去的....论vector的危害性 ...
- mysql 事件 按月分表
/****** 对象: Table Order_201512 脚本日期: 2015/12/18 11:44:23 ******/ /****** 字段数据长度 = 2599 字节 ******/ CR ...
- 使用bat文件执行sql文件
test.bat mysql -uroot -p[password] < test.sql pause test.sql CREATE DATABASE IF NOT EXISTS test_d ...