WebBrowser中比较棘手的问题(自动登录),请各位指点,一定高分
我利用WebBrowser做一个浏览器。要求能够自动登陆,要求能够自动连接页面。要求能够自动的将页面中的表格中的数据自动保存下来。
自动登陆部分我在http://www.163.com中测试可以通过,但在包含有框架页中就无法实现自动登陆的功能。
下面是困扰我几天的问题,大家看看我的代码问题出在哪个地方。同时希望高手们为我调试一下。
我需要自动登陆的页面 http://stbet.com
procedure TForm1.LoginFrameset(document: IHTMLDocument2);
var
index: Integer;
ole_index: OleVariant;
frame_dispatch: IDispatch;
framed: IHTMLWindow2;
obj_user : Olevariant;
obj_pass : Olevariant;
obj_submit : Olevariant;
begin
if document = nil then
exit;
try
for index := 1 to document.Frames.Length do
try
ole_index := index-1;
frame_dispatch := document.Frames.Item(ole_index);
obj_user := document.all.item('username',0);
obj_user.value := 'username'; //今后用户名从配置文件中取
obj_pass := document.all.item('passwd',0);
obj_pass.value := '0000'; //今后密码在配置文件中取
obj_submit := document.all.item('Submit2',0);
obj_submit.Click;
if frame_dispatch <> nil then
begin
framed := frame_dispatch as IHTMLWindow2;
NavigateFrameset(framed.document);
end;
except
on E: Exception do
begin
end
end;
except
on E: Exception do
begin
Application.MessageBox(PChar(E.Message),
PChar('Exception'));
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
LoginFrameset(WebBrowser1.Document as IHTMLDocument2);
end;
自动登陆部分我在http://www.163.com中测试可以通过,但在包含有框架页中就无法实现自动登陆的功能。
下面是困扰我几天的问题,大家看看我的代码问题出在哪个地方。同时希望高手们为我调试一下。
我需要自动登陆的页面 http://stbet.com
procedure TForm1.LoginFrameset(document: IHTMLDocument2);
var
index: Integer;
ole_index: OleVariant;
frame_dispatch: IDispatch;
framed: IHTMLWindow2;
obj_user : Olevariant;
obj_pass : Olevariant;
obj_submit : Olevariant;
begin
if document = nil then
exit;
try
for index := 1 to document.Frames.Length do
try
ole_index := index-1;
frame_dispatch := document.Frames.Item(ole_index);
obj_user := document.all.item('username',0);
obj_user.value := 'username'; //今后用户名从配置文件中取
obj_pass := document.all.item('passwd',0);
obj_pass.value := '0000'; //今后密码在配置文件中取
obj_submit := document.all.item('Submit2',0);
obj_submit.Click;
if frame_dispatch <> nil then
begin
framed := frame_dispatch as IHTMLWindow2;
NavigateFrameset(framed.document);
end;
except
on E: Exception do
begin
end
end;
except
on E: Exception do
begin
Application.MessageBox(PChar(E.Message),
PChar('Exception'));
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
LoginFrameset(WebBrowser1.Document as IHTMLDocument2);
end;
...全文
相关推荐
C# webbrowser实现自动登录淘宝
不含有第三方插件,用自带的Webbrowser实现; 代码简单易懂;
VB6网页自动化:用COM接口实现遗留系统数据自动填表
网页自动化是现代软件测试和数据采集中的关键技术,其核心原理是通过程序模拟用户操作,与浏览器中的文档对象模型(DOM)进行交互。在Windows平台,COM(组件对象模型)技术为实现这一目标提供了底层支持,允许外部程序直接访问和操作网页元素。这种技术对于处理遗留系统、执行重复性数据录入任务具有重要价值,尤其在无法部署现代自动化框架的封闭环境中。本文以Visual Basic 6.0为例,详细解析如何通过WebBrowser控件和MSHTML对象库,实现对老旧网页表单的自动填写与数据提取,涵盖了元素定位、状态同
Delphi WebBrowser Ole 自动登录网站
Delphi程序实现自动登录网站,采用WebBrowser,或者Ole
C# 用WebBrowser实现的多页面浏览器
当要打开新窗口时,不是弹出IE或其他浏览器,在本身的新tab页中是实现。 可以在此基础上进行多次开发,如进行DOM操作,当然做个什么自动化提交之类的也不在话下了。 --包含源码
webbrowser 自动赋值,自动点击按钮,自动跳转
webbrowser 自动赋值,自动点击按钮,自动跳转,自动加载网页


Windows SDK/API
