|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
很简单啊,其实。
把里面的一部分东西改成记录集就好了:
Sub cc()
'增加一个z变量和rst记录集。
Dim url As String, arr() As String, rng() As String, s, i%, j%, k%, m%, n%, z%, str As String
Dim rst As New ADODB.Recordset
m = 0
n = 0
ReDim s(0 To 10000, 1)
For k = 1 To 70
url = "http://kaijiang.zhcw.com/zhcw/html/qlc/list_" & k & ".html"
With CreateObject("Msxml2.XMLHTTP")
.Open "GET", url, False
.send
HTML = StrConv(.responsebody, vbUnicode, &H804)
rng = Filter(Split(HTML, "</td>"), "center")
arr = Filter(Split(HTML, "</"), "<em")
End With
For i = 1 To UBound(rng) Step 5
s(m, 0) = Split(rng(i), ">")(1)
m = m + 1
Next
For i = 0 To UBound(arr) Step 8
j = 0
Do While j < 8
str = Split(arr(i), ">")(UBound(Split(arr(i), ">")))
j = j + 1
If j = 8 Then s(n, 1) = s(n, 1) & "+ " & str: Exit Do
s(n, 1) = s(n, 1) & str & " "
i = i + 1
Loop
n = n + 1
i = i - 7
Next
Next
'从这里开始改。把里面的二维数组提取出来,写入记录集。
rst.Open "test", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For z = 0 To UBound(s, 1) - 1
rst.AddNew
rst(1) = s(z, 0)
rst(2) = s(z, 1)
rst.MoveNext
Next
'关闭记录集并清空内存
rst.Close
Set rst = Nothing
End Sub |
|