TWebBrowser 如何在网页上自动填写数据?

wangeren 2005-10-09 06:10:31
input 表单元素
a := WebBrowser1.OleObject.document.all.item('name',0); //找到登录用户名的输入框
a.value := 'name;

select 表单元素 下来选择的那种
该怎么写???
...全文
406 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
leizhen2004 2005-10-13
  • 打赏
  • 举报
回复
我想顺便问一句,用程序控制提交表单怎么做?
pengxuan 2005-10-10
  • 打赏
  • 举报
回复
<html>

<head>
<title>新建网页 1</title>
<script>
function aa(){
document.all.D1.value="泰国";
}
</script>
</head>

<body>

<form method="POST" action="--WEBBOT-SELF--">
<select size="1" name="D1">
<option value="中国">中国</option>
<option value="日本">日本</option>
</select><p><input type="button" value="按钮" name="B1" onclick="aa()">
</p>
</form>

</body>

</html>
这是测试用的Html
pengxuan 2005-10-10
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw_TLB, EmbeddedWB,MSHTML;

type
TForm1 = class(TForm)
EmbeddedWB1: TEmbeddedWB;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
EmbeddedWB1.Navigate('C:\Documents and Settings\Administrator\桌面\index2.htm');
end;

procedure TForm1.Button1Click(Sender: TObject);
var IDoc1: IHTMLDocument2;
iELC : IHTMLElementCollection ;
i:integer;
spDisp: IDispatch;
HtmlSelectEle : IHTMLSelectElement;
S2 : string;
oIDocment: IHTMLDocument2;
IHtmlWin:IHTMLWindow2;
begin
oIDocment := EmbeddedWB1.Document as IHTMLDocument2;
EmbeddedWB1.Document.QueryInterface(IHTMLDocument2,IDoc1);
if idoc1<>nil then
begin
ielc:=idoc1.Get_all;
for i:=0 to ielc.length-1 do
begin
spDisp := ielc.item(i, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLSelectElement ,HtmlSelectEle))then
with HtmlSelectEle do
begin
S2:=Type_;
S2:=UpperCase(S2);
if (StrComp(PChar(S2),'SELECT-ONE')=0) then
begin
S2:=name;
if (StrComp(PChar(S2),'D1')=0) then
selectedIndex:=1;
end;
end;
end;
end;
end;

end.

这是选择下拉列表框数据的代码.
aiirii 2005-10-10
  • 打赏
  • 举报
回复
automatic fill out HTML forms with TWebBrowser?

{ To test this code put a TWebBrowser and A TButton component on the form }


function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
i, j: Integer;
FormItem: Variant;
begin
Result := False;
//no form on document
if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
begin
Exit;
end;
//count forms on document
for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
begin
FormItem := WebBrowser.OleObject.Document.forms.Item(I);
for j := 0 to FormItem.Length - 1 do
begin
try
//when the fieldname is found, try to fill out
if FormItem.Item(j).Name = FieldName then
begin
FormItem.Item(j).Value := Value;
Result := True;
end;
except
Exit;
end;
end;
end;
end;


//When the document is complete try to fill out the field homepage with the url
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if FillForm(WebBrowser1, 'homepage', 'http://www.swissdelphicenter.ch') = False then
ShowMessage('Error. Field not available or no Form found.');
end;

// Show the Webbrowser-Progress in Label1
procedure TForm1.WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer);
begin
if ProgressMax = 0 then
begin
label1.Caption := '';
Exit;
end;
try
if (Progress <> -1) and (Progress <= ProgressMax) then
label1.Caption := IntToStr((Progress * 100) div ProgressMax) + '% loaded...'
else
label1.Caption := '';
except
on EDivByZero do Exit;
end;
end;


//For example you can load the page /en/addtip.php to the TWebBrowser
//When the document is Complete the form where you can put your homepage
//address is filled out
procedure TForm1.Button1Click(Sender: TObject);
begin
Webbrowser1.Navigate('http://www.swissdelphicenter.ch/en/addtip.php');
// Show the Titel of the currently active Webpage in the titlebar
// Den Titel der aktuellen Webseite in der Titeleiste anzeigen
Caption := Webbrowser1.OleObject.Document.Title;
end;


wangeren 2005-10-10
  • 打赏
  • 举报
回复
没人回答???
WebBrowserWebBrowser编程技术包括Delphi、C#、VC++、VB等编程资料的集合,其中的 实例大多以Delphi为示例讲解,Delphi7 IDE开发环境。 IE_WebBrowser编程技巧 修改WebBrowser的header信息? Delphi查看WebBrowser提交之前的数据头 用TWebBrowser组件在DELPHI中POST数据和取得网页源文件 在 WebBrowser 中直接载入流,不通过文件 判断下载网页成功 WebBrowser 失去焦点问题的解决 添加到收藏夹和整理收藏夹 使WebBrowser获得焦点 提取网页中所有链接 Web字体大小 Web命令操作 WebBrowser Navigate 中的 参数 EmptyParam Web控件不缓存网页,也不从缓存中读取 禁止WebBrowser复制 CTRL+C 在WebBrowser窗口上模拟KeyBd_Event 在使用WebBrowser控件,先要 初始化和结束程序后要终止化(Initialization & Finalization) 自定义浏览器上下文菜单 自定义浏览器 C#中调用WebBrowser查看源文件的功能 ----------------------------------- WebBrowser与MSHTML 直接在WebBrowser中写HTML字符串 在webbrowser中查找字符串并定位 把图片拷贝进剪贴板 IHTMLDocument的ExecCommand 处理事件的Internet Explorer中的DOM 禁止WebBrowser右键弹出菜单 禁止TWebBrowser图像显示 访问HTML的DOM不使用WebBrowser 如何填写空白(about:blank)页的表单 屏蔽WebBrowser的Javascript 创建运行时的IHTMLDocument而不在WebBrowser内 HOOK Webbrowser 替换WebBrowser的窗口过程 Microsoft.XMLHttp的属性和方法的简介及使用 ------------------------ IE相关的 清空IE缓存 单独删除某一URL的缓存 清空历记录 读取IE历史记录 防止脚本关闭WebBrowser 连接是否有效 InternetCheckConnection res协议可以使浏览器显示储存在资源中HTML 往IE中嵌入工具条 阻断弹出式广告的BHO 自动填表的IE面板插件 使用Delphi开发IE按钮扩展 使用Delphi开发IE右键菜单扩展 IE异步可插入协议扩展 Delphi开发IE下载扩展 创建3721样式的Google搜索扩展 HTML代码过滤技术 GetDefaultBrowser 得到的HTML代码的IE窗口 下载网址wininet ------------------------------- 注意啦,需要HTF 阅读器:http://sites.google.com/site/htfresource/home

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧