|
Public Sub cx()
Dim strURL As String
Dim strData As String
Dim xmlHttp As Object
'Set xmlHttp = CreateObject("MSXML2.XMLHTTP") 'CreateObject("WinHttp.WinHttpRequest.5.1") ' CreateObject("MSXML2.XMLHTTP")
Set xmlHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
'strURL = "https://www.baidu.com/s?wd=%E4%BD%A0%E5%A5%BD"
strURL = "https://www.sneac.edu.cn/pzcjweb/cjcx/srindex.jsp"
Set oDoc = CreateObject("htmlfile")
'--------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------
With xmlHttp
For rowi = 4 To 4
.Open "GET", "https://www.sneac.edu.cn/pzcjweb/cjcx/srindex.jsp", False
.setRequestHeader "If-Modified-Since", "0"
.send
strText = .getAllResponseHeaders '获取所有的回应头信息
cookieText = Split(Split(strText, "Set-Cookie: ")(1), ";")(0)
'Debug.Print cookieText
ken = Split(Split(Split(.responseText, "token")(1), "value=""")(1), """>")(0)
'Debug.Print ken
'Debug.Print .responseText
.Open "POST", "https://www.sneac.edu.cn/pzcjweb/cjcx/kssr.jsp", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" '一般可以不用修改
.setRequestHeader "Referer", "https://www.sneac.edu.cn/pzcjweb/cjcx/srindex.jsp" '进行防盗链处理
.setRequestHeader "Cookie", cookieText
.setRequestHeader "If-Modified-Since", "0" '不读缓存
.send "KSH=" & Cells(rowi, 1) & "&SFZH=" & Cells(rowi, 2) & "&PASSWORD=" & Cells(rowi, 3) & "&SECURITYCODE=&token=" & ken ' 在使用 POST 方式时要才使用.send strData
'KSH=0805151686&SFZH=612324199904221521&PASSWORD=201894hJ&SECURITYCODE=&token=cc3e5ef1a6f0d83c617091a9a8e38ec4
'.Open "POST", strURL, False
'.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'.setRequestHeader "Referer", "http://zk.yhjy.gov.cn:88/"
'.setRequestHeader "If-Modified-Since", "0"
'.setRequestHeader "Cookie", "en0evq452ihp3q3t1ljnycvp"
'.send "__VIEWSTATE=%2FwEPDwUKMTI5ODI2Mjg5MmRk&UserName=" & Cells(rowi, 1) & "&PassWord=" & Cells(rowi, 2) & "&btnlogin=+%E7%99%BB+%E9%99%86+"
'Do While .readyState <> 4
'DoEvents
'Loop
'Debug.Print .responseText
oDoc.body.innerHTML = .responseText
'Debug.Print .responseText
'Debug.Print oDoc.body.innerHTML
Set tr = oDoc.all.tags("Table")(2).Rows
For ci = 0 To 6
Cells(rowi, ci + 5) = tr(ci + 2).Cells(1).innerText
'Debug.Print tr(2).Cells(1).innerText
Next
Next
End With
End Sub
这个代码应该可以查询,不过你的第二行数据有错误 无法查询成绩 |
|