Delphi 访问TWebBrowser显示但不包含在其图像集合中的图像

Delphi 访问TWebBrowser显示但不包含在其图像集合中的图像,delphi,twebbrowser,Delphi,Twebbrowser,网页突然出现在另一个窗口中 关于从电子表格检索IMAG的问题 如果您导航到FF中的页面,您将看到在的左侧有两个图像 蓝色的标题条 但是,如果我将页面加载到TWebBrowser并运行以下代码 procedure TForm1.GetImageCount; var Count : Integer; Doc : IHtmlDocument2; begin Doc := IDispatch(WebBrowser1.Document) as IHtmlDocument2; Count :

网页突然出现在另一个窗口中 关于从电子表格检索IMAG的问题

如果您导航到FF中的页面,您将看到在的左侧有两个图像 蓝色的标题条

但是,如果我将页面加载到TWebBrowser并运行以下代码

procedure TForm1.GetImageCount;
var
  Count : Integer;
  Doc : IHtmlDocument2;
begin
  Doc := IDispatch(WebBrowser1.Document) as IHtmlDocument2;
  Count := Doc.images.length;
  ShowMessageFmt('ImageCount: %d', [Count]);
end;
,消息框报告的计数为1,而不是预期的计数(无论如何,由我) 2.我可以轻松地访问并将显示的第一个图像保存到磁盘,但无法访问 第二个或任何后续的,因为它们不在加载页面的IHtmlDocument2
Images
集合中

所以我的问题是,我如何获得第二个映像以将其保存到磁盘

FF调试器显示web页面中塞满了javascript,这是我想象的 可能是第二幅图像的显示方式,但我不知道如何才能得到它


有什么想法吗?

您链接的站点中的第二个图像位于iframe中。 您可以从事件访问iframe:


保存实际图像已经

您好Martyn,第二个图像位于iframe中,您需要在ondocumentcomplete事件中处理iframe。您好,@whosrdaddy。我会试一试…你也必须考虑到网页通常有两种方式从图像传输到客户端计算机。首先是作为文件,在大多数情况下,它会被保存到临时Internet文件夹中,这样就不必每次都重新下载。网页将图像传输到客户端计算机的另一种方式是通过特殊的图像数据流。这种方法通常用于经常更改的图像,以便它们不会存储在临时Internet文件夹中。另外,请记住,当webiste所有者不希望其他人复制他们的图像时,也会使用第二种方法。您还需要考虑跨域帧。在这种情况下,您将无法访问Frames集合(不过还有其他方法)。基本上,@whosrdaddy应该把他的评论作为答案。@whosrdaddy:谢谢。目前,我无法访问第一个(也是唯一一个)帧元素作为IThmlWindow2的位置,这似乎是我唯一可以访问它的位置,但无法钻取它,因为它的文档成员为零。
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.OleCtrls, SHDocVw, MsHtml;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    procedure WebBrowser1DocumentComplete(ASender: TObject;
      const pDisp: IDispatch; const URL: OleVariant);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure TForm1.FormShow(Sender: TObject);
begin
 WebBrowser1.Navigate('https://www.nbbclubsites.nl/club/8000/uitslagen');
end;

procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject; const pDisp: 

IDispatch; const URL: OleVariant);

var
  currentBrowser: IWebBrowser;
  topBrowser: IWebBrowser;
  Doc : IHtmlDocument2;

begin
  currentBrowser := pDisp as IWebBrowser;
  topBrowser := (ASender as TWebBrowser).DefaultInterface;
  if currentBrowser = topBrowser then
   begin
    // master document
    Doc := currentBrowser.Document as IhtmlDocument2;
    ShowMessageFmt('ImageCount: %d', [Doc.images.length]);
   end
  else
  begin
   // iframe
   Doc := currentBrowser.Document as IhtmlDocument2;
   ShowMessageFmt('ImageCount: %d', [Doc.images.length]);
  end;
end;

end.