|
楼主 |
发表于 2016-6-23 16:06
|
显示全部楼层
Sub wordVBA网抓实例()
Dim mt, mts As Object, m$, n%, i%, k%
Dim reg As Object, xDoc As Object
Set xDoc = CreateObject("msxml2.xmlhttp.6.0")
Set reg = CreateObject("VBscript.regexp")
Documents.Add
With xDoc
For k = 1 To 3 '抓取3页数据,根据实际需要更改
.Open "POST", "http://www.pinble.com/Template/WebService1.asmx/Present3DList", False
.setRequestHeader "Content-Type", "application/json; charset=utf-8"
.setRequestHeader "Referer", "http://www.pinble.com/Lottery.htm"
.send "{pageindex:'" & k & "',lottory:'TC7XCData_jiangS',pl3:'',name:'江苏七星彩',isgp: '0'}"
m = .responseText
With reg
.Global = True: .IgnoreCase = False
.Pattern = "(?:开奖时间|期号|开奖号码)|(?:\d{4}-\d{2}-\d{2})|\d{7}(?!%)"
Set mts = .Execute(m)
n = mts.Count / 3
With ActiveDocument
.Tables.Add Selection.Range, n, 3
.Tables(k).Style = "网格型"
For Each mt In mts
i = i + 1
.Tables(k).Range.Cells(i).Range.Text = mt
Next
End With
End With
Selection.EndKey wdStory
Selection.Range.InsertAfter Chr(13)
Selection.EndKey wdStory
i = 0
Next
End With
Set xDoc = Nothing: Set reg = Nothing
End Sub
|
评分
-
1
查看全部评分
-
|