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  更新时间:

 

posted on 2020-11-23 09:08  滔Roy  阅读(390)  评论(0编辑  收藏  举报

导航