在线等...自动填表错误
我用vb WebBrowser1_DocumentComplete 自动填写并登录https://wwws.ameritrade.com/apps/LogIn
老是说
行 35
字符 3
错误 'form.query_data' 为空或不是对象
有错,问我脚本是否继续,我按是否都能登成功。
vb代码
Private Sub Command10_Click()
WebBrowser1.navigate "https://wwws.ameritrade.com/apps/LogIn"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim vDoc, vTag
Dim i As Integer
Set vDoc = WebBrowser1.document
For i = 0 To vDoc.All.length - 1
If UCase(vDoc.All(i).tagName) = "SELECT" Then
Set vTag = vDoc.All(i)
If vTag.Name = "StartPage" Then vTag.Value = "LOGIN_STOCKS"
End If
If UCase(vDoc.All(i).tagName) = "INPUT" Then
Set vTag = vDoc.All(i)
If vTag.Type = "text" Or vTag.Type = "password" Then
'List1.AddItem vTag.Name
Select Case vTag.Name
Case "USERID"
vTag.Value = "x888"
Case "PASSWORD"
vTag.Value = "vc654"
End Select
ElseIf vTag.Type = "submit" Then
vTag.Click
End If
End If
Next i
End Sub
========================================================
行35 if (form.query_data.value.indexOf("VCE_Details") != -1) { form.query_data.value = ""; }
以下是部分js
====================
<HTML>
<HEAD>
<TITLE>Log on to
TD Ameritrade
</TITLE>
<!-- VERSION: pr-ctlstr--pp13-clientsys - dev_WEB_2011.12_CostBasisEChange_BUILD_03 -->
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="icon" href="/favicon.ico" />
<!-- version is appended to universal.css and js to ensure lastest scripts and css on logon-->
<link rel="stylesheet" type="text/css" href="/amer/css/universal.css?dev_WEB_2011.12_CostBasisEChange_BUILD_03">
<script language="JavaScript" src="/amer/scripts/universal.js?dev_WEB_2011.12_CostBasisEChange_BUILD_03"></script>
<script language="javascript" src="/amer/scripts/login.js?dev_WEB_2011.12_CostBasisEChange_BUILD_03"></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
if (window!= top)
top.location.href=location.href;
var form;
function init(){
form = document.li;
if (form.USERID.value == "") form.USERID.focus();
post_deviceprint(); //needed to get browser info from pm_fp.js
loginCookieCheck();
getSetCookie();
var playerVersion = deconcept.SWFObjectUtil.getPlayerVersion();
var flashVersion = playerVersion.major + "." + playerVersion.minor + "." + playerVersion.rev;
form.flashVersion.value = flashVersion;
//vceQueryCheck("main", form.USERID);
}
var scount = 0;
function submitForm() { // when user presses enter
scount++;
if (scount == 1) {
if (form.query_data.value.indexOf("VCE_Details") != -1) { form.query_data.value = ""; }
form.submit();
}
}
function submitFromLogOn() { // when user presses the log on button. didn't have it usng submitForm, so i kept separate
if (form.query_data.value.indexOf("VCE_Details") != -1) { form.query_data.value = ""; }
form.submit();
}
function getSetCookie()
{
var start_pos, end_pos;
if (document.cookie.indexOf("startpage") != -1 && document.getElementById('SP'))
{ start_pos = document.cookie.indexOf("startpage");
end_pos = document.cookie.indexOf(";",start_pos);
document.getElementById('SP').options.selectedIndex = document.cookie.substring(start_pos+10, end_pos);
}//end if
}//end function getSetCookies
function setCookie()
{
if(document.getElementById('SP')){
var exdate=new Date()
exdate.setDate(10000)
fresh_data = document.getElementById('SP').options.selectedIndex;
document.cookie="startpage =" +fresh_data+ "; expires ="+exdate;
}
}//end function setCookies
// -->
</SCRIPT>
</HEAD>
<BODY onLoad="init();">
<div class="contentFrame">
<table id="nullNav" cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<tr>
<td class="logo"><a href="http://www.tdameritrade.com" style="background-color:transparent">
<img src='/amer/images/logo.gif' alt='Home'>
</a></td>
<td class="link" width="100%" align="right">
<ul>
<li> <a href="http://www.tdameritrade.com">TD Ameritrade</a> </li>
</ul>
</td>
</tr>
<tr>
<td colspan="2" class="navBorder"> </td>
</tr>
<tr>
<td colspan="2" valign="top"><div class="hr" style="background-color:#CCCCCC;"> </div></td>
</tr>
<tr>
<td colspan="2" valign="top"><div class="hr" style="background-color:#EEEEEE;height:4px;"> </div></td>
</tr>
</table>
<form name="li" action="/cgi-bin/apps/LogIn" method="POST" enctype="application/x-www-form-urlencoded" onSubmit="submitForm(); return false;" autocomplete="off">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tbody>
<tr>
<td colspan="2" style="width:550px">
<div class="messagingItemsContainer errorIconContainer" id="errorMessages" style="display:none">
<div class="boxSevereErrorTop">
<div class="r1"> </div><div class="r2"> </div><div class="r3"> </div>
</div>
<div id="errorText" class="boxSevereErrorText">
<span class="errorIcon" id="cookieErrorMessageIcon" style="display:none;"></span>
<p id="cookieErrorMessage" style="display:none;">
For your protection, you must update your browser security settings before you can access the Web site.
To do this, follow the instructions on the <a href="#" onClick="popLogOnHelp('/cgi-bin/apps/u/LoginHelp?pagehandler=PHCheckSettings')">Check your Settings</a> page.
</p>
</div>
<div class="boxSevereErrorBottom">
<div class="r3"> </div><div class="r2"> </div><div class="r1"> </div>
</div>
</div>
<script type="text/javascript">
multipleMessages("errorText");
</script>
<!-- Broadcast Message Template -->
</td>
</tr>
<tr>
<td style="vertical-align:top">
<div class="boxTopLogin boxBottomLogin" style="width:270px; height:232px">
<table border="0" cellpadding="0" cellspacing="0" id="login" class="boxGradient">
<tbody>
<tr>
<th><span class="title"></span></th>
</tr>
<tr>
<td>
<div class="fieldLabel">
UserID <span class="secure"></span>
</div>
<div class="fieldElement">
<input name="USERID" type="text" class="text" maxlength="15">
</div>
<div class="fieldLabel">Password</div>
<div class="fieldElement">
<input name="PASSWORD" type="password" maxlength="20">
</div>
<div class="fieldElement" style="margin:0;">
<a href="/cgi-bin/apps/u/ForgotPassword" class="loginLinks" style="line-height: 12px; font-size: 10px; float:right;margin-right:5px" onClick="">Forgot your password?</a>
</div>
<div class="fieldLabel" style="clear:both;">Choose a start page</div>
<div class="fieldElement">
<select id="SP" name="StartPage" onChange="setCookie()">
<option value="">Home</option>
<option value="LOGIN_BALANCES">Balances & Positions</option>
<option value="LOGIN_QUOTES">Quotes</option>
<option value="LOGIN_ORDER_STATUS">Order Status</option>
<option value="LOGIN_STOCKS">Trade Stocks</option>
<option value="LOGIN_OPTIONS">Trade Options</option>
<option value="LOGIN_MUTUAL_FUNDS">Trade Mutual Funds</option>
<option value="LOGIN_TRADING_TOOLS">Trading Tools</option>
</select>
<script>
var vceIsWealthRuler = false;
var TED, $vceContainer, $tedButton, wrWidth, wrHeight, wrTop, wrLeft, tedButtonPos;
var ENCRYPTED_LOGIN_IDENTIFIERS = '';
var TED_ALLOWED = '';
TED_ALLOWED = (TED_ALLOWED!='');
VCEdetails = function(display, top, left, width, height) {
this.iframeInit = false;
this.display = (display) ? display : "hidden";
this.defaultWidth = 360;
this.defaultHeight = 360;
this.defaultTop = 70;
this.defaultLeft=0;
if(tedButtonPos && $tedButton){ this.defaultLeft = (parseInt(tedButtonPos.left) + $tedButton.width()) - this.defaultWidth; }
this.top = (top) ? top : this.defaultTop;
this.left = (left) ? left : this.defaultLeft;
this.width = (width) ? width : this.defaultWidth;
this.height = (height) ? height : this.defaultHeight;
this.agentURL = "https://wwws.ameritrade.com/activeagentwebui/Agent.aspx";
this.agentLauncherURL = "https://wwws.ameritrade.com/activeagentwebui/AgentCommunicator.aspx";
this.iframeStart = '<iframe id="vceIframe" name="vceIframe" src="';
this.iframeEnd = '" allowtransparency="true" scrolling="no" frameborder="0"></iframe>';
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
[最优解释]
先设置控件属性WebBrowser1.Silent True,再加入代码
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Silent = True
End Sub