webbrowser 怎么模拟点击网页或框架内链接

2025-02-23 20:39:09
推荐回答(1个)
回答1:

// WB:打开网页的TWebBrowser对象,Href:热链地址
//模拟点击TWebBrowser的图片
procedure ImageClick(WB: TWebBrowser; Href: string);
var
i: Word;
Document: IHtmlDocument2;
str: string;
begin
for i := 0 to WB.OleObject.Document.Images.Length - 1 do
begin
Document := WB.Document as IHtmlDocument2;
Str := (Document.Images.Item(i, 0) as IHTMLImgElement).Href;
if Pos(Href, str) <> 0 then
begin
((Document.Images.Item(i, 0) as IHTMLImgElement) as IHTMLElement).Click;
end;
end;
end;