【已解决】需要进行多次操作获取数据,能否用Post或Get一次完成?
本帖最后由 .個朲綉√ 于 2011-11-6 09:12 编辑While 1
_get_Post($ie_Cookie)
_get_No1($ie_Cookie)
_get_No2($ie_Cookie)
;就是想知道这三次操作,能不能合为一次操作,或者说放在一个函数中进行。
WEnd
Func _get_Post($ie_Cookie);提交必要的数据
$poststr="Cookie"
$xmlhttp.open("post","http://www.baidu.com",false)
$xmlhttp.setRequestHeader("Accept","application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/msword, */*")
$xmlhttp.setRequestHeader("Referer", "http://www.baidu.com")
$xmlhttp.setRequestHeader("Accept-Language", "zh-CN")
$xmlhttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; BOIE9;ZHCN)")
$xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
$xmlhttp.setRequestHeader("Accept-Encoding","gzip, deflate")
$xmlhttp.setRequestHeader("Host","www.baidu.com")
$xmlhttp.setRequestHeader("Content-Length",StringLen($poststr))
$xmlhttp.setRequestHeader("Connection"," Keep-Alive")
$xmlhttp.setRequestHeader("Pragma","no-cache")
$xmlhttp.setRequestHeader("Cookie",$ie_Cookie)
$xmlhttp.send($poststr)
$para_txt=$xmlhttp.Responsetext
If $para_txt=="" Then
Return 0
EndIf
Return 1
EndFunc
Func _get_No1($ie_Cookie);提交查询
$xmlhttp.open("get","http://www.baidu.com",False)
$xmlhttp.setRequestHeader("Accept","application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/msword, */*")
$xmlhttp.setRequestHeader("Referer", "http://www.baidu.com")
$xmlhttp.setRequestHeader("Accept-Language", "zh-CN")
$xmlhttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; BOIE9;ZHCN)")
$xmlhttp.setRequestHeader("Accept-Encoding","gzip, deflate")
$xmlhttp.setRequestHeader("Host","www.baidu.com")
$xmlhttp.setRequestHeader("Connection"," Keep-Alive")
$xmlhttp.setRequestHeader("Cookie",$ie_Cookie)
$xmlhttp.send()
$para_txt=$xmlhttp.Responsetext
If $para_txt=="" Then
Return 0
EndIf
Return 1
EndFunc
Func _get_No2($ie_Cookie);这个为自动GET的数据,不知道是否必需。
$xmlhttp.open("get","http://http://www.baidu.com/s?wd=Autoit&rsv_spt=1&issp=1&rsv_bp=0&ie=utf-8&tn=baiduhome_pg&inputT=3668",False)
$xmlhttp.setRequestHeader("Accept","application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/msword, */*")
$xmlhttp.setRequestHeader("Referer", "http://www.baidu.com");这里必需为上一个GET网址。
$xmlhttp.setRequestHeader("Accept-Language", "zh-CN")
$xmlhttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; BOIE9;ZHCN)")
$xmlhttp.setRequestHeader("Accept-Encoding","gzip, deflate")
$xmlhttp.setRequestHeader("Host","www.baidu.com")
$xmlhttp.setRequestHeader("Connection"," Keep-Alive")
$xmlhttp.setRequestHeader("Cookie",$ie_Cookie)
$xmlhttp.send()
$para_txt=$xmlhttp.Responsetext
If $para_txt=="" Then
Return 0
EndIf
$xdll = StringRegExp($para_txt,'(?s)总流量\(M\):(\d+)',1)
Return 1
EndFunc
可能我表达的不够清楚,有些词不达意吧,所以搜了半天没搜到,我再描述一下吧,希望有人能理解。
就是我首先要在一个页面输入数据,然后提交,这第一步是要Post的。 (如函数_get_Post)
提交完数据后,第二步要选择查询的方式,如选择日期等,然后再提交,这一步是Get的。 (如函数_get_No1)
在第二次提交后,我在抓包中发现有第三次Get, (如函数_get_No2) ,最终获取数据。
不知道能否用一个函数完成这些操作,当然我说的一个函数,并不是说合并在一起
而是希望简化操作,如下:(不知具体写法,希望高人指点)
$poststr="Cookie"
$xmlhttp.open("post","http://www.baidu.com",false)
$xmlhttp.setRequestHeader("Accept","application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/msword, */*")
$xmlhttp.setRequestHeader("Referer", "http://www.baidu.com")
$xmlhttp.setRequestHeader("Accept-Language", "zh-CN")
$xmlhttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; BOIE9;ZHCN)")
$xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
$xmlhttp.setRequestHeader("Accept-Encoding","gzip, deflate")
$xmlhttp.setRequestHeader("Host","www.baidu.com")
$xmlhttp.setRequestHeader("Content-Length",StringLen($poststr))
$xmlhttp.setRequestHeader("Connection"," Keep-Alive")
$xmlhttp.setRequestHeader("Pragma","no-cache")
$xmlhttp.setRequestHeader("Cookie",$ie_Cookie)
$xmlhttp.send($poststr)
$xmlhttp.open("get","http://www.baidu.com",False)
$xmlhttp.open("get","http://http://www.baidu.com/s?wd=Autoit&rsv_spt=1&issp=1&rsv_bp=0&ie=utf-8&tn=baiduhome_pg&inputT=3668",False)
你的第4个代码,不就是一起的吗,应该行的 回复 1# .個朲綉√
了解一下winhttp和wininet的编程相关吧。 回复.個朲綉√
了解一下winhttp和wininet的编程相关吧。
republican 发表于 2011-10-10 08:30 http://www.autoitx.com/images/common/back.gif
哦,不知道是否可以实现,分成三段代码来做三个动作,感觉有些多余。
我这就去查查winhtt和wininet相关资料。 用来干麻的! 这么简单的事情,为什么不自己试试是否可行呢?
一开始,无所谓搞得清搞不清原理,自己动手做做,反过来再看文档,才会有更多收获。 这么简单的事情,为什么不自己试试是否可行呢?
一开始,无所谓搞得清搞不清原理,自己动手做做,反过来再 ...
bakefish 发表于 2011-10-10 21:52 http://www.autoitx.com/images/common/back.gif
谢谢前辈指点,您说的对,我自己再琢磨一下。
第二步get数据,直接复制到地址栏也可查询,是否可以au3中也可省略?我试的结果都不对,不知是我写错了,还是必须post
自己再试试吧,谢谢您! 姐姐也来看看 应该不难把~~~ 我在另一个帖子下附件,居然说我金币不足!..于是我就来到了这里!... 此问题已解决,可以连续GET操作的,不错....
Func _login()
$xmlhttp.open("get","http://www.baidu.com",False)
$xmlhttp.send()
$para_txt=$xmlhttp.Responsetext
$lt = StringRegExp($para_txt,'(?m)(?<="lt").*?"(\V+)" />',1)
$poststr="username=百度&password=密码<="&$lt&"&_eventId=submit"
$xmlhttp.open("post","http://www.baidu.com",false)
$xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
$xmlhttp.send($poststr)
$para_txt=$xmlhttp.Responsetext
$lt = StringRegExp($para_txt,'(?m)(?<="lt").*?"(\V+)" />',1)
$poststr="asHelp=0&loginPwd=密码<="&$lt&"&_eventId=submit&operatorId=百度"
$xmlhttp.open("post","http://www.baidu.com",false)
$xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
$xmlhttp.send($poststr)
$para_txt=$xmlhttp.Responsetext
$xmlhttp.open("get","http://www.baidu.com",False)
$xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
$xmlhttp.send("")
$para_txt=$xmlhttp.Responsetext
$xmlhttp.open("get","http://www.baidu.com",False)
$xmlhttp.send("")
$para_txt=$xmlhttp.Responsetext
EndFunc
路过学习! 新手,看了还是不明白$xmlhttp.send(),到底send什么? 直接是看不懂呀
页:
[1]