本帖最后由 lihaiboking 于 2012-6-2 18:08 编辑
网站地址:http://jpxww.com/bbs/login.asp
验证码图片:http://jpxww.com/bbs/Dv_GetCode.asp?t=0.8693561639179401
附上:
我最后用XMLhttp获取的方法:#include <Array.au3>
$oHTTP = ObjCreate("microsoft.xmlhttp")
$files = @ScriptDir & "\CODE.bmp" ;验证码图片保存位置
$t=RegCreatePng()
$url = "http://jpxww.com/bbs/Dv_GetCode.asp?t=" & $t ;验证码地址
$u1="http://jpxww.com/bbs/login.asp" ;论坛地址
$oHTTP.open("get",$u1,False)
$oHTTP.Send()
$r1=BinaryToString($oHTTP.responseBody)
If StringInStr($r1,"欢迎您:游客!") Then MsgBox(0,"获取网站信息成功","当前状态:未登陆状态")
;这步连接网站正常,能正常获取信息
;以下为取得COOKIE
$h1=$oHTTP.getAllResponseHeaders()
$ss=StringRegExp($h1,"Set-Cookie:\s*(.+)\r",3)
$xx=""
UBound($ss)
If UBound($ss)<>0 Then
For $y=0 To UBound($ss)-1
$xx=$xx & $ss[$y]
Next
EndIf
StringReplace($xx,"path=/bbs/","")
StringReplace($xx,"path=/","")
;按httpwatch 截获的数据,进行GET验证码操作
$oHTTP.open("get",$url,True)
$ohttp.setRequestHeader("Accept","*/*")
$ohttp.setRequestHeader("Referer","http://jpxww.com/bbs/login.asp")
$ohttp.setRequestHeader("Accept-Encoding","gzip, deflate")
$ohttp.setRequestHeader("Host","jpxww.com")
$ohttp.setRequestHeader("Accept-Language","zh-cn")
$ohttp.setRequestHeader("Connection","Keep-Alive")
$ohttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 691; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; VENUS_IE_ADDON-0.2.7.95; .NET CLR 3.5.30729; .NET CLR 3.0.4506.2152)")
$ohttp.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded ");
$ohttp.setRequestHeader("Cookie",$xx & "CNZZDATA80399653=cnzz_eid=36084216-1338627028-&ntime=1338627028&cnzz_a=0&retime=1338627050515&sin=<ime=1338627050515&rtime=0")
$oHTTP.Send()
Sleep(1000)
;这里有点迷糊,不加判断的话,ReadyState=1
Do
Sleep(100)
$oHTTP.Send()
until $ohttp.ReadyState=4
$h1=$oHTTP.getAllResponseHeaders()
MsgBox(0,"返回HTTP头信息",$h1)
MsgBox(0,"状态",$oHTTP.status)
;保存验证码数据到文件,但每次服务器返回空:Content-Length: 0,这也是我弄不明白的地方
;此验证码图片在IE新窗口中打开也为空白,我怀疑应该就是问题解决的方向。
$f=FileOpen($files,16+8+2)
FileWrite($f,$ohttp.responseBody)
FileClose($f)
Func RegCreatePng() ;图片验证码地址后的随机数
Local $code
$code &= 'function regcreatepng()' & @CRLF
$code &= '{' & @CRLF
$code &= 'var nvalue = Math.random()' & @CRLF
$code &= 'return nvalue' & @CRLF
$code &= '}' & @CRLF
$nJS = ObjCreate("ScriptControl")
$nJS.language = "JavaScript"
$nJS.addcode($code)
$nRegCreatePng = $nJS.Run("regcreatepng")
Return $nRegCreatePng
EndFunc ;==>RegCreatePng
|