|
楼主 |
发表于 2015-3-10 23:22
|
显示全部楼层
本帖最后由 onlycxb 于 2015-3-11 08:32 编辑
mckawayi 发表于 2015-3-10 22:54
按照您的代码,多页取值,就会发现某些页面会出现“403“禁止访问提示。。。。
Sub t()
Dim html, db ...
简单测试一下(代码未优化),运行1000次没有出错- Option Explicit
- Sub t()
- Dim html, db, i%, j%, k%, rowx, TD, TR, arrdata(1 To 100000, 1 To 18), P
-
- For P = 1 To 1000
- Set html = CreateObject("htmlfile")
- With CreateObject("msxml2.xmlhttp")
- .Open "GET", "http://data.eastmoney.com/bbsj/201412/yjbb/ggrq/desc/" & P & ".html", False '以取第1页数据为例
- .send
- html.body.innerhtml = .responsetext
- End With
- Set db = html.all.tags("table")
- For i = 0 To db.Length - 1
- If db(i).classname = "tab1" Then
- Set rowx = db(i).Rows
- For Each TR In rowx
- j = j + 1
- k = 0
- For Each TD In TR.Cells
- k = k + 1
- If j > 2 Then arrdata(j - 2, k) = TD.innertext
- Next TD
- Next TR
- End If
- Next i
- Set html = Nothing
- Set db = Nothing
- Set rowx = Nothing
- Next P
- Cells.Clear
- [a1].Resize(j - 2, 18) = arrdata
- End Sub
复制代码
|
|