|
- Sub SubmitForm()
- Dim yzm As String
- Dim myurlin As String, myurlout As String
- Dim HTTPReq
- Dim htmlStr As String
- Dim arrScore(1 To 6)
- Dim arrS
- Dim s As String
- Dim sht As Worksheet
- Dim postData As String
-
- On Error Resume Next
- Set sht = Sheets("Sheet2")
- Set HTTPReq = New MSXML2.XMLHTTP60
-
- '定义被提交的URL地址
- myurlin = "http://cx.ahzsks.cn/pugao/2024/pgcj2024yanlian_in-13a9ff06-3218-478b-8c21-deb1bf4520d7.php"
- myurlout = "http://cx.ahzsks.cn/pugao/2024/pgcj2024yanlian_out-13a9ff06-3218-478b-8c21-deb1bf4520d7.php"
-
- For r = 2 To sht.Range("A1").End(xlDown).Row
-
- HTTPReq.Open "GET", myurlin, False
- HTTPReq.send
-
- ' 等待响应完成
- Do While HTTPReq.ReadyState <> 4 Or Len(HTTPReq.responseText) < 3000
- DoEvents
- Loop
-
- If HTTPReq.ReadyState = 4 And HTTPReq.Status = 200 Then
- htmlStr = HTTPReq.responseText
- End If
-
- yzm = 获取字段("4""/>[\s\S]+?", "[\s\S]+?<", htmlStr)
- postData = "sfzh=" & sht.Cells(r, "B") & "&xm=" & sht.Cells(r, "D") & "&ksh=" & sht.Cells(r, "C") & "&yzm=" & yzm
- ' Debug.Print postData
-
- '打开XMLHttpRequest对象
- HTTPReq.Open "POST", myurlout, False
-
- '设置POST请求头
- HTTPReq.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
- '发送POST请求
- HTTPReq.send (postData)
- '输出响应信息
- htmlStr = HTTPReq.responseText
- Debug.Print htmlStr
- htmlStr = Replace(htmlStr, Chr(10), "")
- arrS = Split(htmlStr, "<tr align=""center"">")
- For i = 3 To UBound(arrS) - 1
- s = arrS(i)
- sht.Cells(r, i + 2) = 获取字段("<td colspan='2'>", "</td>", s)
- Next i
- sht.Cells(r, 9) = Split(Split(arrS(1), "</td>")(1), ">")(1) '总分
- sht.Cells(r, 10) = Split(Split(arrS(1), "</td>")(3), ">")(1)
- Next r
- Debug.Print "结束"
- End Sub
- Private Function 获取字段(str1 As String, str2 As String, Str As String) As String
- On Error Resume Next
- Dim RegExp As Object
- Set RegExp = CreateObject("vbscript.regexp")
- With RegExp
-
- .Global = False
- .IgnoreCase = False
- .Pattern = str1 & "(\d\d\d\d)" & str2
- 获取字段 = .Execute(Str)(0).submatches(0)
- End With
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|