本帖最后由 .個朲綉√ 于 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)
|