我不太懂,用笨方法点击了两层frame,呵呵 你自己去掉一层就可以了procedure TForm1.btn2Click(Sender: TObject); var // Source:string; ole_index: OleVariant; frame_dispatch,frame_dispatch2: IDispatch; frame_win,frame_win2: IHTMLWindow2; doc2,frame_doc,frame_doc2: IHTMLDocument2; J:integer; spDisp: IDispatch; IDoc1,IDoc2: IHTMLDocument2; ielc: IHTMLElementCollection ; ihtml:IHTMLElement; iane:IHTMLAnchorElement; begin ole_index:=1;//这里是主页面的第二个frame doc2:=wb1.Document as IHTMLDocument2; frame_dispatch := doc2.Frames.Item(ole_index); if frame_dispatch <> nil then begin frame_win := frame_dispatch as IHTMLWindow2; frame_doc := frame_win.Document; frame_doc.QueryInterface(IHTMLDocument2,iDoc1); mmo1.Lines.Add(frame_doc.Body.OuterHtml); mmo1.Lines.Add('======================================='); frame_dispatch2 := iDoc1.Frames.Item(0);//这里是上面第二个frame中的第一个frame, if frame_dispatch2 <> nil then begin frame_win2 := frame_dispatch2 as IHTMLWindow2; frame_doc2 := frame_win2.Document; frame_doc2.QueryInterface(IHTMLDocument2,iDoc2); mmo1.Lines.Add(frame_doc2.Body.OuterHtml); ielc:=idoc2.Get_all; for J:=0 to ielc.length-1 do begin Application.ProcessMessages; spDisp := ielc.item(J, 0); if SUCCEEDED(spDisp.QueryInterface(IHTMLAnchorElement ,iane))then begin if AnsiContainsText(iane.href,'你链接的关键词') then //http://www.xxx.com/pc.php pc.php就可以了 begin ihtml:=ielc.item(J,0) as IHTMLElement; ihtml.click; Mmo1.Lines.Add('点击成功'); end; end; end; end; end; end;这方法比较笨,你可以遍历所有frame或直接获取frame序号
http://blog.csdn.net/bdmh/article/details/6069485
你自己去掉一层就可以了procedure TForm1.btn2Click(Sender: TObject);
var
// Source:string;
ole_index: OleVariant;
frame_dispatch,frame_dispatch2: IDispatch;
frame_win,frame_win2: IHTMLWindow2;
doc2,frame_doc,frame_doc2: IHTMLDocument2;
J:integer;
spDisp: IDispatch;
IDoc1,IDoc2: IHTMLDocument2;
ielc: IHTMLElementCollection ;
ihtml:IHTMLElement;
iane:IHTMLAnchorElement;
begin
ole_index:=1;//这里是主页面的第二个frame
doc2:=wb1.Document as IHTMLDocument2;
frame_dispatch := doc2.Frames.Item(ole_index);
if frame_dispatch <> nil then
begin
frame_win := frame_dispatch as IHTMLWindow2;
frame_doc := frame_win.Document;
frame_doc.QueryInterface(IHTMLDocument2,iDoc1);
mmo1.Lines.Add(frame_doc.Body.OuterHtml);
mmo1.Lines.Add('=======================================');
frame_dispatch2 := iDoc1.Frames.Item(0);//这里是上面第二个frame中的第一个frame,
if frame_dispatch2 <> nil then
begin
frame_win2 := frame_dispatch2 as IHTMLWindow2;
frame_doc2 := frame_win2.Document;
frame_doc2.QueryInterface(IHTMLDocument2,iDoc2);
mmo1.Lines.Add(frame_doc2.Body.OuterHtml);
ielc:=idoc2.Get_all;
for J:=0 to ielc.length-1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLAnchorElement ,iane))then
begin
if AnsiContainsText(iane.href,'你链接的关键词') then //http://www.xxx.com/pc.php pc.php就可以了
begin
ihtml:=ielc.item(J,0) as IHTMLElement;
ihtml.click;
Mmo1.Lines.Add('点击成功');
end;
end;
end;
end;
end;
end;这方法比较笨,你可以遍历所有frame或直接获取frame序号
没试过 跟据项目的需要 直接用 webbrowser1.navigate('超链接地址'),不管框架了