Delphi TWebBrowser[7] 获取网页图片(静态和动态)
Delphi TWebBrowser[7] 获取网页图片(静态和动态)
1、静态图常用方法:
uses WinInet
function GetLocalFileNameFromIECache(url:string; var LocalFileName:string):DWORD;
var
D: Cardinal;
T: PInternetCacheEntryInfo;
begin
result := S_OK;
D := 0;
T:=nil;
GetUrlCacheEntryInfo(PChar(Url), T^, D);
Getmem(T, D);
try
if (GetUrlCacheEntryInfo(PChar(Url), T^, D)) then
LocalFileName:=T^.lpszLocalFileName
else
Result := GetLastError;
finally
Freemem(T, D);
end;
end;
2、动态图
uses MsHtml, ActiveX, ClipBrd
var
iIndex: Integer;
Rang:IHTMLControlRange;
ImgSel: IHTMLControlElement;
begin
iIndex := 0; //所需的图片在网页中出现的顺序
Rang := ((IHTMLDocument2(WebBrowser1.Document).body as HTMLBody).createControlRange) as IHTMLControlRange;
ImgSel := IHTMLDocument2(WebBrowser1.Document).images.item(iIndex,EmptyParam)as IHTMLControlElement;
Rang.add(ImgSel);
Rang.execCommand('Copy', False, 0);
Image1.Picture.Assign(ClipBoard);
end;
创建时间:2020.11.23 更新时间:
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!