找回密码
 加入
搜索
查看: 4847|回复: 4

[IE类操作] 验证码图片无法通过xmlhttp winhttp inet获取下载,求高手给看一下。

[复制链接]
发表于 2012-6-2 18:06:10 | 显示全部楼层 |阅读模式
本帖最后由 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
发表于 2012-6-2 19:24:27 | 显示全部楼层
回复 1# lihaiboking

Do Not Use Object to Download the verifyimage.

Or u will have to dealing with the Cookies. In some website, it makes no sense.
 楼主| 发表于 2012-6-2 19:33:03 | 显示全部楼层
二楼是什么意思,看不明白,能不能说的具体点。
发表于 2012-6-2 20:21:05 | 显示全部楼层
回复 3# lihaiboking
不要使用对象来下载验证图像
 楼主| 发表于 2012-6-3 00:18:42 | 显示全部楼层
有没有解决的方案,看来这个验证码只能在IE中获取?等待高手给个不在IE中获取的方法。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 22:38 , Processed in 0.094416 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表