|
楼主 |
发表于 2012-7-17 14:16
|
显示全部楼层
本帖最后由 liucqa 于 2014-2-18 14:17 编辑
调用 getMultiPageData函数,通过Post获取首页数据和下一次做POST提交的VIEWSTATE等参数
- Private Sub getMultiPageData(objWinhttp As Object, URL As String, strItemName As String)
- Dim tt$, postdata$, drptitle$, drpZzdj$, PagingForwardTo$, ScriptManager2, eventtarget$, page%, Maxpage%, sht As Worksheet
- ScriptManager2 = "ctl00$UpdatePanel1|ctl00$cph_content$drpZzdj" '切换专业资质的选择(首页),post参数
- eventtarget = "ctl00$cph_content$drpZzdj" '切换专业资质的选择(首页),post参数
- drptitle = "ECB034F6E40C4E33A5F8C7587D112CB6" '这个参数在专业资质的页面是不变的,其他链接没有核对。
- drpZzdj = dicMapIndex(strItemName)
- PagingForwardTo = 1 'post提交的页码
- n = 1 '记录输出数据的数组下标
- Maxpage = 1 '最大页码
- '***************打开选择的专业资质页面*******************
- Application.StatusBar = "正在获取" & strItemName & "的首页..." & ",累计用时" & Format(Timer - t, "0.0秒"): DoEvents
- tt = ""
- With objWinhttp
- .Option(6) = 1 '支持重定向,此例中有无均可
- '下面是POST的字符串构建过程。
- postdata = "ctl00$ScriptManager2=" & ScriptManager2 & _
- "&__EVENTTARGET=" & EncodePostdata(eventtarget) & _
- "&__EVENTARGUMENT=" & _
- "&__LASTFOCUS=" & _
- "&__VIEWSTATE=" & EncodePostdata(viewstate) & _
- "&__VIEWSTATEENCRYPTED=" & _
- "&__EVENTVALIDATION=" & EncodePostdata(eventvalidation) & _
- "&ctl00$WidthPixel=" & _
- "&ctl00$HeightPixel=" & _
- "&ctl00$cph_content$drpTitle=" & drptitle & _
- "&ctl00$cph_content$drpZzdj=" & drpZzdj & _
- "&ctl00$cph_content$txtEnterName=" & _
- "&ctl00$cph_content$txtDay=" & txtDay & _
- "&ctl00$cph_content$GridViewPaging1$txtGridViewPagingForwardTo=" & PagingForwardTo & _
- "&ctl00$cph_content$GridViewPaging1$btnForwardToPage=Go"
- .Open "POST", URL, False
- .setRequestHeader "Referer", "http://www.gzgcjg.com/gzqypjtx/Estimate/ZY/MainQueryMarkZY.aspx?clearPaging=true" '提交来源
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 'POST提交必备
- .setRequestHeader "Content-Length", Len(postdata) 'POST提交的长度信息
- .setRequestHeader "Connection", "Keep-Alive"
- .send (postdata) ' 如果操作系统为XP,只有打上括号才能提交。(猜测可能和Unicode编码有关)
- tt = .responseText
- With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") '调试用,数据放入剪贴板
- .SetText tt
- .PutInClipboard
- End With
-
- If CheckServerError(objWinhttp.Status, tt) Then
- Application.StatusBar = False
- Application.ScreenUpdating = True
- Set objWinhttp = Nothing
- Set dicMapIndex = Nothing
- End
- End If
- viewstate = Split(Split(tt, "__VIEWSTATE"" value=""")(1), """")(0) '获取VIEWSTATE参数
- eventvalidation = Split(Split(tt, "__EVENTVALIDATION"" value=""")(1), """")(0) '获取EVENTVALIDATION参数
- Maxpage = Val(Split(Split(tt, "共<font color='red'>")(2), "</font>页")(0)) '获取最大页码数,为后继的Post循环做准备
- End With
- End Sub
复制代码
演示程序到此就结束了,在实际应用中,得到最大页码之后,还要通过循环POST取得每个页面的数据,具体要提交的参数可以通过抓包软件得到,这里不再赘述。
|
评分
-
2
查看全部评分
-
|