提取网页form中所有控件的名字和值.txt

来自「大量Delphi开发资料」· 文本 代码 · 共 42 行

TXT
42
字号
提取网页Form中所有控件的名字和值(Name & Value)

procedure THtmlTestFrm.GetInputNameList(AList: TStrings);
var
  HTMLDocument:IHTMLDocument2;
  All,AllForms:IHTMLElementCollection;
  Index,Item:OleVariant;
  i,Count:integer;
begin
  HTMLDocument := WebBrowser1.Document as IHTMLDocument2;
  All:=HTMLDocument.all;
  AList.Clear;
  Index:=0;    //表示第一个Form
  AllForms:=HTMLDocument.forms;
  Item:=AllForms.item(varempty,Index);
  Count:=Item.elements.Length;
  for i:=0 to Count-1 do
  begin
    AList.Add(Item.elements.item(i).Name);
  end;
end;

procedure THtmlTestFrm.GetInputValueList(AList: TStrings);
var
  HTMLDocument:IHTMLDocument2;
  All,AllForms:IHTMLElementCollection;
  Index,Item:OleVariant;
  i,Count:integer;
begin
  HTMLDocument := WebBrowser1.Document as IHTMLDocument2;
  All:=HTMLDocument.all;
  AList.Clear;
  Index:=0;
  AllForms:=HTMLDocument.forms;
  Item:=AllForms.item(varempty,Index);
  Count:=Item.elements.Length;
  for i:=0 to Count-1 do
  begin
    AList.Add(Item.elements.item(i).value);
  end;
end;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?