日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

html 自动填表,Delphi WEB网页自动填表

發布時間:2023/12/20 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html 自动填表,Delphi WEB网页自动填表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Delphi中利用webbrowser控件來實現自動填表,此例為一模板,稍作修改可用來自動申請QQ、郵箱、論壇ID之類(不包含驗證碼識別)。

代碼如下:

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,

Forms,

Dialogs, StdCtrls,MSHTML, SHDOCVW,IdGlobal;

type

TMainFrm = class(TForm)

btnTest: TButton;

edURL: TEdit;

Label1: TLabel;

procedure btnTestClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

MainFrm: TMainFrm;

implementation

{$R *.dfm}

procedure FillIEForm(aURL:string);

procedure

DoWithHtmlElement(aElementCollection:IHTMLElementCollection);

var

k:integer;

vk:oleVariant;

Dispatch: IDispatch;

HTMLInputElement:IHTMLInputElement;

HTMLSelectElement:IHTMLSelectElement;

HTMLOptionElement: IHTMLOptionElement;

HTMLTextAreaElement: IHTMLTextAreaElement;

HTMLFormElement:IHTMLFormElement;

HTMLOptionButtonElement:IHTMLOptionButtonElement;

begin

for k:=0 to aElementCollection.length -1 do

begin

Vk:=k;

Application.ProcessMessages;

Dispatch:=aElementCollection.item(Vk,0);

if

Succeeded(Dispatch.QueryInterface(IHTMLInputElement,HTMLInputElement))

then

begin

With HTMLInputElement do//單行文本

begin

if (UpperCase(Type_)='TEXT') or (UpperCase(Type_)='PASSWORD')

then

begin

value:='text';

end

else if (UpperCase(Type_)='CHECKBOX') then//復選框

begin

checked:=true;

end

else if (UpperCase(Type_)='RADIO') then//單選框

begin

checked :=true;

end;

end;

end

else if

Succeeded(Dispatch.QueryInterface(IHTMLSelectElement,HTMLSelectElement))

then

begin

With HTMLSelectElement do//下拉框

begin

selectedIndex :=1;

end;

end

else if

Succeeded(Dispatch.QueryInterface(IHTMLTEXTAreaElement,HTMLTextAreaElement))

then

begin

with HTMLTextAreaElement do//多行文本

begin

value :='textarea';

end;

end

else if

Succeeded(Dispatch.QueryInterface(IHTMLOptionElement,HTMLOptionElement))

then

begin

with HTMLOptionElement do//下拉選項

begin

//處理

end;

end

else if

SUCCEEDED(Dispatch.QueryInterface(IHTMLFormElement,HTMLFormElement))then

begin

with HTMLFormElement do//表單

begin

//處理

end;

end

else if

SUCCEEDED(Dispatch.QueryInterface(IHTMLOptionButtonElement,HTMLOptionButtonElement))then

begin

//不明

//處理

end

else

//showmessage('other');

;

end;

end;

var

ShellWindow: IShellWindows;

Web: IWebBrowser2;

Dispatch: IDispatch;

i,j:integer;

IEAddress:string;

HTMLDocument:IHTMLDocument2;

ElementCollection:IHTMLElementCollection;

FrameWindow:IHTMLWindow2;

Vi,Vj:OLEVariant;

HTMLFrameBase :IHTMLFrameBase ;

HTMLFrameElement:IHTMLFrameElement ;

HTMLIFrameElement:IHTMLIFrameElement;

begin

ShellWindow := CoShellWindows.Create;

for i:=0 to ShellWindow.Count -1 do

begin

Vi:=i;

Dispatch:=Shellwindows.item(Vi);

if Dispatch=nil then continue;

Dispatch.QueryInterface(IWebBrowser2,Web);

if Web<>nil then

begin

IEAddress:=Web.LocationURL;

if Pos(aURL,IEAddress)>0 then

begin

Web.Document.QueryInterface(IHTMLDocument2,HTMLDocument);

if HTMLDocument<>nil then

begin

if HTMLDocument.frames.length =0 then//無框架

begin

ElementCollection:=HTMLDocument.Get_All;

DoWithHtmlElement(ElementCollection);

end

else//有框架

begin

for j:=0 to HTMLDocument.frames.length -1 do

begin

Vj:=j;

Dispatch:=HTMLDocument.frames.item(Vj);

//?if

Succeeded(Dispatch.QueryInterface(IHTMLFrameBase,HTMLFrameBase)

if Succeeded(Dispatch.QueryInterface(IHTMLWindow2,FrameWindow))

then

begin

//?DoWithHtmlElement(FrameWindow.document.all);

end;

End;

end;

end;

end;

End;

end;

end;

procedure TMainFrm.btnTestClick(Sender: TObject);

begin

FillIEForm(edUrl.Text);

end;

end.

單個frames的輸入

var o : Olevariant; begin //找到登錄用戶名的輸入框 o :=

WebBrowser.OleObject.document.all.item('LoginUserID',0); o.value :=

'TEST';

//找到登錄密碼的輸入框

o := WebBrowser.oleobject.document.all.item('LoginPassword',0);

o.value := 'TEST'

//第一個表單提交 WebBrowser.oleobject.document.Forms.Item(0,

0).submit;

{ //或者用指定表單名稱提交 o

:=WebBrowser.oleobject.document.all.item('Login',0); o.Click;

//點擊操作,對其它對象也可同樣操作 }

end; 多個frames的輸入,FrameIndex為Frame的序號

var o : Olevariant; begin //找到登錄用戶名的輸入框 o :=

WebBrowser.oleobject.document.documentelement.document.frames.item(FrameIndex).document.all.item('LoginUserID',0);

o.value := 'TEST';

//找到登錄密碼的輸入框 o :=

WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.all.item('LoginPassword',0);

o.value := 'TEST'

//第一個表單提交

WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.Forms.Item(0,

0).submit;

{ //或者用指定表單名稱提交 o

:=WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex)..document.all.item('Login',0);

o.Click;

//點擊操作,對其它對象也可同樣操作 }

end;

網頁的源碼不能讀取,可能由于不能讀源碼,所以也不能用IHTMLDocument2及IHTMLElementCollection;

WebBrowse.Document.All.Item('控件ID',0).Value := 'AAa';

之類的來提交表單。我在網上查了很多資料,也不能用。類似以下的:

var?doc?:?IHTMLDocument2;?all?:?IHTMLElementCollection;?len,i?:?integer;?item?:?OleVariant;?HtmlInputEle?:?IHTMLInputElement;?SubmitBtn?:?IHTMLButtonElement;?spDisp?:?IDispatch;?begin?if?WebBrowser1.Document?<>?nil?then?begin?doc:=WebBrowser1.Document?as?IHTMLDocument2;?all:=doc.all;?len:=all.Length;?for?i:=0?to?len-1?do?begin?spDisp:=all.item(i,varEmpty);?if?SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement?,HtmlInputEle))?then?begin?if?HTMlInputEle.name?=?'UserID'?then?HtmlInputEle.value?:=?'test';?if?HTMlInputEle.name?=?'Passwd'?then?HtmlInputEle.value?:=?'test';?end;?if?SUCCEEDED(spDisp.QueryInterface(IHTMLButtonElement?,SubmitBtn))?then?if?SubmitBtn.name?=?'submitButtonName'?then?SubmitBtn.click();?end;?end;?end;

總結

以上是生活随笔為你收集整理的html 自动填表,Delphi WEB网页自动填表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。