打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
WebBrowser里网页根据文字判断来点击链接
uses  ActiveX, ComObj, MSHTML;
根据连接文字点击连接-    一般情况下的连接
Procedure HTMLClinkByText(text:string;Wbr:TWebBrowser);
var
doc:IHTMLDocument2;
len,I:integer;
item:OleVariant;
all:IHTMLElementCollection;
begin
doc:=Wbr.Document as IHTMLDocument2;
all:=doc.Get_links;
len:=all.length;
for I:=0 to len-1 do
begin
item:=all.item(I,varempty);
if pos (text,item.InnerText)>0 then      //判断连接文字包含内容
begin
Wbr.Navigate(item.href);
end;
end;
end;
使用的时候,要点击包含"联系"这两个字的链接
HTMLClinkByText('联系',WebBrowser1);
----------------------------------------------------------------------------------------------
Iframe 里面的连接点击
function   GetFrame(FrameNo: Integer): IWebbrowser2;
var
OleContainer: IOleContainer;
enum: IEnumUnknown;
unk: IUnknown;
Fetched: PLongint;
begin
while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages;
if Assigned(Webbrowser1.document) then
begin
Fetched := nil;
OleContainer := Webbrowser1.Document as IOleContainer;
OleContainer.EnumObjects(OLECONTF_EMBEDDINGS, Enum);
Enum.Skip(FrameNo);
Enum.Next(1, Unk, Fetched);
Result := Unk as IWebbrowser2;
end
else
Result := nil;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
doc,frm:IHTMLDocument2;
iw:IWebbrowser2;
i,j,len: integer;
all:IHTMLElementCollection;
item:OleVariant;
begin
doc:=Webbrowser1.Document as IHTMLDocument2;
for i:=0 to doc.frames.length-1 do
begin
iw:=GetFrame(i);
frm:=iw.Document as IHTMLDocument2;
all:=frm.Get_links;
len:=all.length;
for j:=0 to len-1 do
begin
item:=all.item(j,varempty);
ListBox1.Items.Add(item.InnerText+' ~ '+item.href); //文字和相应的连接
//根据上面那个Pos判断  item.InnerText  里包含你要点击的内容
//然后  Webbrowser1.Navigate(item.href);  ................................
end;
end;
end;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
获得一个网页的所有的URL(WebBrowser)
Delphi Webbrowser IE 窗口选择中,选中的文字内容
如何取得网页框架中的内容(300分)
Delphi中WebBbrowser的编程
Delphi实现HTMLWebBrowser实现HTML界面
TWebBrowser访问IFrame
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服