WebBrowser中比较棘手的问题(自动登录),请各位指点,一定高分
solly 2004-10-10 09:20:08 我利用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;