|
回91楼- Function URLEncodePlus(strURL)
- 'ANSI编码,空格处理成+号
- Dim i
- Dim tempStr
- For i = 1 To Len(strURL)
- If Asc(Mid(strURL, i, 1)) < 0 Then
- tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, i, 1)))), 2)
- tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, i, 1)))), Len(CStr(Hex(Asc(Mid(strURL, i, 1))))) - 2) & tempStr
- URLEncodePlus = URLEncodePlus & tempStr
- ElseIf (Asc(Mid(strURL, i, 1)) >= 65 And Asc(Mid(strURL, i, 1)) <= 90) Or _
- (Asc(Mid(strURL, i, 1)) >= 97 And Asc(Mid(strURL, i, 1)) <= 122) Or _
- (Asc(Mid(strURL, i, 1)) >= 48 And Asc(Mid(strURL, i, 1)) <= 57) Then
- URLEncodePlus = URLEncodePlus & Mid(strURL, i, 1)
- Else
- tempStr = Mid(strURL, i, 1)
- Select Case tempStr
- Case ".", "-", "~", "_" '如果发现网站有其他不需要编码的字符,放在这里
- URLEncodePlus = URLEncodePlus & tempStr
- Case " "
- URLEncodePlus = URLEncodePlus & "+"
- Case Else
- URLEncodePlus = URLEncodePlus & "%" & Hex(Asc(tempStr))
- End Select
- End If
- Next
- End Function
- Sub 按钮1_单击()
- Dim url, html
- url = "http://zsw.bjtu.edu.cn/JHFS/Default.aspx"
- Set html = CreateObject("htmlfile")
- n = 1
- With CreateObject("msxml2.xmlhttp")
- .Open "get", url, False
- .send
- html.body.innerhtml = .responsetext
- Set tb = html.all.tags("tr")
- For i = 0 To tb.Length - 1
- If tb(i).classname = "common_title" Then
- n = n + 1
- For j = 0 To tb(i).Cells.Length - 1
- Cells(n, j + 1) = tb(i).Cells(j).innertext
- Next
- End If
- Next
- For p = 2 To 3 '只做了3页
- VIEWSTATE = URLEncodePlus(html.getElementById("__VIEWSTATE").Value)
- VIEWSTATEGENERATOR = URLEncodePlus(html.getElementById("__VIEWSTATEGENERATOR").Value)
- PREVIOUSPAGE = URLEncodePlus(html.getElementById("__PREVIOUSPAGE").Value)
- EVENTVALIDATION = URLEncodePlus(html.getElementById("__EVENTVALIDATION").Value)
- pd = "__EVENTTARGET=ctl04%24zsjh"
- pd = pd & "&__EVENTARGUMENT=Page%24" & p
- pd = pd & "&__LASTFOCUS="
- pd = pd & "&__VIEWSTATE=" & VIEWSTATE
- pd = pd & "&__VIEWSTATEGENERATOR=" & VIEWSTATEGENERATOR
- pd = pd & "&__PREVIOUSPAGE=" & PREVIOUSPAGE
- pd = pd & "&__EVENTVALIDATION=" & EVENTVALIDATION
- pd = pd & "&ctl04%24sysq=%B2%BB%CF%DE"
- pd = pd & "&ctl04%24nf=%B2%BB%CF%DE"
- pd = pd & "&ctl04%24xkml=%B2%BB%CF%DE"
- pd = pd & "&ctl04%24zymc=%B2%BB%CF%DE"
- pd = pd & "&ctl04%24pyfs=%B2%BB%CF%DE"
- .Open "POST", url, False
- .setRequestheader "Host", "zsw.bjtu.edu.cn"
- .setRequestheader "User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:32.0) Gecko/20100101 Firefox/32.0"
- .setRequestheader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
- .setRequestheader "Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"
- .setRequestheader "Accept-Encoding", "gzip, deflate"
- .setRequestheader "Referer", "http://zsw.bjtu.edu.cn/JHFS/Default.aspx"
- .setRequestheader "Connection", "keep-alive"
- .setRequestheader "Content-Type", "application/x-www-form-urlencoded"
- .send (pd)
- html.body.innerhtml = .responsetext
- Set tb = html.all.tags("tr")
- For i = 0 To tb.Length - 1
- If tb(i).classname = "common_title" Then
- n = n + 1
- For j = 0 To tb(i).Cells.Length - 1
- Cells(n, j + 1) = tb(i).Cells(j).innertext
- Next
- End If
- Next
- Next
- End With
- End Sub
- Sub 按钮2_单击()
- Range("a2:h65536").ClearContents
- End Sub
复制代码 |
|