|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 fxl447098457 于 2018-6-25 12:58 编辑
试过了,做了下微调,考试次数和最高分都可以查询出来了。
Sub getdata()
Dim http As Object, dom As Object, 工号 As Long, Url As String, btnSubmit As String, hfQuery As String
Dim VIEWSTATE As String, VIEWSTATEGENERATOR As String, EVENTVALIDATION As String, PostData As String
Dim joinid As String, ts As String, in_dex As String, s_ign As String, url2 As String, Strtext$, 成绩
Dim res As Object, result As Object, i As Integer, scount As Integer, arr(), Max_Score
Set http = CreateObject("msxml2.xmlhttp")
Set dom = CreateObject("htmlfile")
工号 = 128402
Url = "https://sgmwhsfs.wjx.cn/resultquery.aspx?activity=15976219"
With http
.Open "GET", Url, False
.send
dom.body.innerhtml = .responsetext
VIEWSTATE = zm(dom.getElementById("__VIEWSTATE").Value)
VIEWSTATEGENERATOR = zm(dom.getElementById("__VIEWSTATEGENERATOR").Value)
EVENTVALIDATION = zm(dom.getElementById("__EVENTVALIDATION").Value)
EVENTVALIDATION = zm(dom.getElementById("__EVENTVALIDATION").Value)
btnSubmit = zm(dom.getElementById("btnsubmit").Value)
hfQuery = zm("20000|" & 工号)
PostData = "__VIEWSTATE=" & VIEWSTATE & "&__VIEWSTATEGENERATOR=" & VIEWSTATEGENERATOR & _
"&__EVENTVALIDATION=" & EVENTVALIDATION & "&btnSubmit=" & btnSubmit & "&hfQuery=" & hfQuery
.Open "POST", Url, False
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Referer", ""
.send (PostData)
dom.body.innerhtml = .responsetext
Set res = dom.getElementById("divData")
If InStr(res.innerhtml, "query__amount") = 0 Then
scount = 1
Max_Score = Val(Split(res.innerhtml, "form__items--rt figcaption form__score""><STRONG>")(1))
Else
scount = Val(Split(res.innerhtml, "<DIV class=query__amount>共")(1)) '考试次数
For i = 1 To scount Step 1
ReDim Preserve arr(1 To i)
Set result = dom.getElementById("divData" & i)
joinid = result.joinid: ts = result.ts: s_ign = result.parterSign: in_dex = result.Index
url2 = "https://sgmwhsfs.wjx.cn/handler/JoinDetail.ashx?activityid=15976219&joinid=" & _
joinid & "&ts=" & ts & "&sign=" & s_ign & "&index=" & in_dex
.Open "GET", url2, False
.send
Strtext = .responsetext
arr(i) = Val(Split(Strtext, "form__items--rt figcaption form__score'><strong>")(1))
Next i
Max_Score = Application.Max(arr)
End If
MsgBox "工号为" & 工号 & "考试次数为:" & scount & "次,最高分数为:" & Max_Score
End With
End Sub
Private Function zm(s As String)
With CreateObject("htmlfile")
.write "<script></script>"
zm = .Parentwindow.eval("encodeURIComponent('" & s & "')")
End With
End Function
|
|