|
楼主 |
发表于 2024-11-25 18:04
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub Main()
Const UserName As String = "vbatest" '假设的账户
Const UserPwd As String = "12341234"
Dim strText As String
Dim strJS As String
Dim strJSFun As String
Dim pwdRtn As String
With CreateObject("MSXML2.XMLHTTP")
'1、获取js文件的js代码:
.Open "GET", "http://img1.soufun.com/secondhouse/image/magent/js/RSA.js", False
.Send
strJS = .responsetext
.Open "GET", "http://img1.soufun.com/secondhouse/image/magent/js/BigInt.js", False
.Send
strJS = strJS & ";" & .responsetext
.Open "GET", "http://img1.soufun.com/secondhouse/image/magent/js/Barrett.js", False
.Send
strJS = strJS & ";" & .responsetext
'2、截取函数cmdEncrypt的执行语句,并把获取str_userpwd文本框的值的代码替换为我们的密码变量。
.Open "GET", "http://agent.fang.com/", False
.Send
strText = .responsetext
strJSFun = Mid(strText, InStr(strText, "setMaxDigits("))
strJSFun = Left(strJSFun, InStr(strJSFun, "$(""#str_userpwd"").attr(""value"", pwdRtn);") - 1)
strJSFun = Replace(strJSFun, "$(""#str_userpwd"").attr(""value"")", "'" & UserPwd & "'")
'3、将strJS和strJSFun结合后执行,取出pwdRtn值:
pwdRtn = JSEval(strJS & ";" & strJSFun & ";pwdRtn")
'4、登录
.Open "POST", "http://agent.soufun.com/DealCenterLogin.aspx?codev=" & Round(Rnd() * 10000), False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send "str_username=" & UserName & "&str_userpwd=" & pwdRtn & "&Submit1=%B5%C7++%C2%BC"
Debug.Print .getallresponseheaders '有三个Set-Cookie表明登录成功
End With
End Sub
Function JSEval(s As String) As String
With CreateObject("MSScriptControl.ScriptControl")
.Language = "javascript"
JSEval = .Eval(s)
End With
End Function
参考这位大神的写法,在 JSEval = .Eval(s) 提示错误 |
|