| 发表于:2007-02-27 12:48:221楼 得分:0 |
首先要在uses中引用mshtml单元. 代码及分析如下: var hform:ihtmlformelement; hdoc:ihtmldocument2; hall:ihtmlelementcollection; hinput:ihtmlinputelement; iw:iwebbrowser2; hlen,tmploop:integer; vk:olevariant; dispatch:idispatch; begin if assigned(webbrowse1) then ///保证网页里有内容;即已经打开一个网页! begin hdoc:=webbrowse1.document as ihtmldocument2; hall:=hdoc.get_all; hlen:=hall.get_length; ////以上几步的操作为:将浏览器控件里的内容赋给hdoc.取其所有标识,并算出总数; ////下面的操作为:按总数循环找到用户名和密码的edit;并赋值; for tmploop:=0 to hlen-1 do begin vk:=tmploop; dispatch:=hall.item(vk,0); if succeeded(dispatch.queryinterface(ihtmlinputelement,hinput)) then ///如果此标识是一个edit控件….. begin ////下面这里的uppercase是必需的!防止因大小写的不同而判断失误! ///下面的 "text "是由网页里的内容来确定的.也就是说你要判断就必需根据具体网页代码来! ///密码框和用户名处是一样的! if uppercase(hinput.type_)= 'text ' then hinput.value:= 'tresss ' else if uppercase(hinput.type_)= 'password ' then hinput.value:= 'tresss '; end; if succeeded(dispatch.queryinterface(ihtmlformelement,hform)) and (uppercase(hform.name)= 'theform ') then ///此处是form提交.如果从html发现只有一个form的话那第二个条件是非必需的! ///而且也不一定要判断name属性,也可以根据其它属性来判断. hform.submit; end; ////for end; end; //if end; end; 到此,,一个自动登陆的例子就作好了..如果要实现灌水的话,,可以将hinput:ihtmlinputelement换成htext:ihtmltextareaelement,也就相当于memo控件.将用户名的赋值换成是发言的赋值就好;当然这里还可以换成是其它的,如单选等…具体内容可以查看mshtml里的列表! | | |
|