|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
以下网爬代码总觉得不够理想,还能怎么优化?网爬数据到底有没有最优方案?呵呵
- Sub kao()
- [a2:c2] = Split("统计时间 在线人数 波动值")
- Dim regx, i%, mh, tt, p, m, PostData
-
- Set regx = CreateObject("vbscript.regexp")
- regx.Pattern = "<td>(.*?)</td>" '注意中文的括号(全角)
- regx.Global = True
-
- For p = 1 To 7
-
- PostData = "PageIndex=" & p & "&__RequestVerificationToken=CfDJ8Oxgi0PF5dtKgteCEWR3ZKKzhWUHnMIkczUHpAA12yTUk-KolOww9ZYTIz6y8-tIfgH2yCgFH-DCVvplmsOa2aRf8VuJtozMmUX_clPPMks-XT6jl3vSufB9_l7nCiRKDdhrvCjTdqPEx7XgPW2-DTk"
- With CreateObject("msxml2.xmlhttp")
- .Open "POST", "http://www.77tj.org/tencent/", False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .send (PostData)
- tt = .responsetext
- End With
- tt = Split(tt, "<table class=""gridview"">")(1)
-
- Set mh = regx.Execute(tt)
- For i = 0 To mh.Count - 1 Step 3
- m = m + 1
- For j = 1 To 3
- Cells(m + 2, j) = Replace(mh(i + j - 1).submatches(0), "+", "+")
- Next
- Next
- Next
-
- Columns("A:C").Columns.AutoFit
- MsgBox "job is okey"
- End Sub
复制代码
|
|