希望专家看看针对我的问题看有没有好的解决方案?
目前问题:
1、在运行过程中,POST和获取信息太慢(可以用龟速形容),专家帮忙看下代码哪里有问题?
2、在账号和密码都正确的情况下,时而判断失败,时而判断成功,是否跟问题1有直接关系?
备注:代码中以有论坛的账号和密码!Global $UserName, $password
Global $LoginPage, $PostPage, $CheckPage
Global $xmlhttp, $bodytext
Global $PostData, $Formhash, $cookietime
$UserName = 'abcd1234'
$password = 'abcd1234'
$CheckPage = "http://bbs.ieyos.com/"
$LoginPage = "http://bbs.ieyos.com/member.php?mod=register"
$PostPage = 'http://bbs.ieyos.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=LAeAE&inajax=1'
$xmlhttp = ObjCreate("MSXML2.XMLHTTP.3.0")
;===========以下是检测帐号是否登录,如果登陆就先退出==============
$xmlhttp.open("GET", $CheckPage, False)
$xmlhttp.send()
$bodytext = BinaryToString($xmlhttp.responseBody, 1)
If StringInStr($bodytext, '个人中心') Then
$Formhash = StringRegExp($bodytext, 'formhash=(.*?)"', 3)
$xmlhttp.open("GET", 'http://bbs.ieyos.com/home.php?mod=space&do=pm', False)
$xmlhttp.send()
EndIf
;=================以下是获取postdata===============================
$xmlhttp.open("GET", $LoginPage, False)
$xmlhttp.send()
$bodytext = BinaryToString($xmlhttp.responseBody, 1)
$cookietime = StringRegExp($bodytext, 'name="cookietime".*?value="(.*?)"', 3)
$Formhash = StringRegExp($bodytext, 'name="formhash" value="(.*?)"', 3)
If Not @error Then $PostData = 'formhash=' & $Formhash[0] & '&referer=http%3A%2F%2Fbbs.ieyos.com%2Fmember.php%3Fmod%3Dregister' & '&loginfield=username&username=' & $UserName & '&password=' & $password & '&questionid=0&answer=' & $cookietime[0]
;~ If Not @error Then $PostData = 'formhash=' & $Formhash[0] & '&loginfield=username&username=' & $UserName & '&password=' & $password & '&questionid=0&answer=&cookietime=' & $cookietime[0]
;===========以下是发送post数据,并检测登录是否成功================
$xmlhttp.open("POST", $PostPage, False)
$xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
;~ $xmlhttp.setRequestHeader('referer', 'http://autoitx.com/')
$xmlhttp.send($PostData)
$bodytext = BinaryToString($xmlhttp.responseBody, 1)
ConsoleWrite($bodytext)
If StringInStr($bodytext, '欢迎您回来') Then
MsgBox(0, "", "登录成功!")
Else
MsgBox(0, "", "登录失败!")
EndIf
|