如何读出TWebbrowser中的INPUT框里的内容(包括滚动文本框和下拉框)? (0分)

D

dana

Unregistered / Unconfirmed
GUEST, unregistred user!
用下面的方法为何读不出滚动文本框和下拉框?
procedure TForm1.PutData;
var
ShellWindow: IShellWindows;
nCount: integer;
spDisp: IDispatch;
i,j,X: integer;
vi: OleVariant;
IE1: IWebBrowser2;
IDoc1: IHTMLDocument2;
iELC : IHTMLElementCollection ;
S,S2 : string;
HtmlInputEle : IHTMLInputElement;
HtmlSelEle : IHTMLSelectElement;
begin
ShellWindow := CoShellWindows.Create;
nCount := ShellWindow.Count;

for i := 0 to nCount - 1 do
begin
vi := i;
spDisp := ShellWindow.Item(vi);
if spDisp = nil then continue;
spDisp.QueryInterface( iWebBrowser2, IE1 );
if IE1 <> nil then
begin
IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);
if iDoc1 <> nil then
begin

ielc:=idoc1.Get_all;

for j:=0 to ielc.length-1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement ,HtmlInputEle))then
with HtmlInputEle do
begin
S2:=Type_;
S2:=UpperCase(S2);
//我把所有的input都填上 try , checkbox 都打勾
if (StrComp(PChar(S2),'TEXT')=0) or (StrComp(PChar(S2),'PASSWORD')=0) then
value :='try' //S:=S+#9+Value
else if StrComp(PChar(S2),'CHECKBOX')=0 then
begin
checked := True;
end;
end;
if SUCCEEDED(spDisp.QueryInterface(IHTMLselectelement ,HtmlSelEle))then
with HtmlSelEle, Memo1.Lines do
begin
S:=S+#9+IntToStr(selectedIndex+1); //这个是获取数据了
end;
end; //END FOR
Memo2.Lines.Add(S);
exit;
end;
end;
end;
end;
 
因為兩者是不一樣的,
單行的類似 edit 的是 IHtmlInputElement ;
多行的類似 memo 的是 IHtmlTextAreaElement 。
 
那么下拉框呢?
 
我是使用這兩個搭配的~

IHTMLSelectElement;
IHTMLOptionElement;

 
请问如何搭配使用,我还是读不到滚动文本框的下拉框?
这是为什么?
 
还有想问一下,你是如何点击到“提交”按钮,当网页上有两个以上提交按钮时如何点击
到指定的按钮?
 
如果你不懂 HTML 語法的話,建議去找個教學網頁,這樣子來學會快很多,
同時你也就瞭解為何要搭配使用了。

接下來,去下載一個 OLEView 的軟體 ,裡頭你可看見一堆介面,也是很有幫助。


指定下拉框可單獨使用 IHtmlSelectElement.selectedIndex 來指定,
但我都搭配 IHTMLOptionElement ,可指定為某個特定字串的內容。

至於按鈕...,想想按鈕的作用吧,通常有特殊之用途,一般是提交使用,
一個網頁上如有兩個提交按鈕時,代表網頁上有兩個 Form ,
過濾一下便可得到啦;甚至可用第幾個按鈕來點擊。 ^^
 
var HtmlSelEle : IHTMLSelectElement

if SUCCEEDED(spDisp.QueryInterface(IHTMLselectelement ,HtmlSelEle))then
with HtmlSelEle do
begin
HtmlSelEle.name //这样还是读不出下拉框。
end;


我单击提交是用: web1.oleobject.document.Forms.Item(0, 0).submit; //提交
可这样有的网站不支持。有较好的方法吗?
能贴出你的源码让我看一下吗?谢谢!
 
大哥!救命,以上的方法在ie4下不能自动填写,该怎么办?
 
可以像控制button类一样控制Ie上的"Button"吗?
 
web1.oleobject.document.Forms.Item(0, 0).submit
這樣是不行的,因為有些網站最上端有廣告,而有些廣告本身帶有 Form ,
你單指定第一個 Form 的話,有時會指到廣告。

可用類似

if SUCCEEDED(spDisp.QueryInterface(IHTMLFormElement,FormEle))then

加上 FormEle.name 或 FormEle.action

來判斷是否為你要指定的 Form.

再用 FormEle.submit 來提交。

 
可是这样当form 没有name时无法提交,
当 formele.action激活的是aa.asp时,没有执行提交事件,而是刷新了页面。
 
應該不會,給個網頁來試試吧!
 
你能试一下阿里巴巴的网站的发布信息,我怎么也没办法点击到“提交”的按钮?
网址:http://china.alibaba.com/bin/user/signin
请帮忙试一下!谢谢!


 
可以呀,你試著分析網頁,看看能否從 WebBrowser 得到以下物件。
六個 INPUT ,一個 Form.

然後就得到按鈕名稱(SignIn)啦,有了之後點擊(click)按鈕就好啦。

只要能分析出,便可以對它動作,分析不出,就代表你的程式碼有問題。



INPUT Index: 1 Name:Done Type:hidden Value:/bin/home/ehomepage
INPUT Index: 2 Name:cc Type:hidden Value:1
INPUT Index: 3 Name:step Type:hidden Value:2
INPUT Index: 4 Name:UserId Type:text Value:
INPUT Index: 5 Name:password Type:password Value:
INPUT Index: 6 Name:SignIn Type:submit Value: 登 ?

Form Name:form Action:/bin/user/signin Method:post Target:
 
当form 没有name 时是默认为form吗?
我是这样提交按钮,
第一种:web1.oleobject.document.Forms.Item(butt,0).submit; //提交
第二种:
if SUCCEEDED(spDisp.QueryInterface(IHTMLFormElement,FormEle))then
begin
FormEle.onsubmit;
end;
第三种:
item:=doc.forms.item('Form',emptyparam);//‘LOGON’是表单的名字
item.submit;

可是这三种都无法提交?
因为它的Action是/bin/user/signin 所以都只是刷新action指定的页,
而没有实际提交,这是为何?

 
我是使用第二種

if SUCCEEDED(spDisp.QueryInterface(IHTMLFormElement,FormEle))then
begin
FormEle.submit; // 注意此行
end;
 
不好意思我写错了。
我就是用FormEle.submit; ,可是这样就是刷新本网页,而不是提交?
你可以试一下阿里巴巴的网站,没有实际的提交,我弄不明白为什么?
网址:http://china.alibaba.com/bin/user/signin
还有,有的网站有进行输入框的检测。
如当“姓名”框没填时会出现一个script语句的提示showmessae
如何跳过此提示,或者如何屏蔽?
比如21世纪商务
网址:http://www.21bc.com/free_business/up_free_sd2.asp?bclass=170200&nclass=电脑及软件代理&obclass=170000&onclass=商业代理
 
阿里巴巴的网站, 試過啦,可以呀!
使用點擊「登錄」按鈕,OK!
使用表單提交(form.submit),OK!



至於避開輸入框的檢測,最好的辦法便是遵守遊戲規則,隨便填一個值
進去,不然便要判斷啦,有的檢測是寫在 button.onclick 事件中,這個
用 form.submit 便可跳過;有的寫在 form.onsubmit 中,這個就麻煩啦,
我還沒遇過有此需求,所以無方法應對。

至於21世纪商务便是第二類,使用 form.onsubmit 的,所以不知方法.....
或許可將 form.onsubmit 取消看看。(我不會)

 
整句代码我是这样写的有错吗?这样并没有提交网页,只是刷新而已。
function TForm1.PutData1:boolean; //KeyWords
var spDisp: IDispatch; j: integer; IDoc1: IHTMLDocument2;
iELC : IHTMLElementCollection ; formele:IHTMLFormElement;
begin
if web <> nil then
begin
web.Document.QueryInterface(IHTMLDocument2,iDoc1);
if iDoc1 <> nil then
begin
ielc:=idoc1.Get_all;
for j:=0 to ielc.length-1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLFormElement,FormEle))then
begin
FormEle.submit;
end;
end;
end;
result:=true;
end
else result:=false;
end;

 
顶部