0

在特定网站上,如果我打开一个新的 IE 实例,我已经通过身份验证,只要同时有另一个打开的 IE 实例,我以前登录过。如果我从 Delphi 打开一个 tWebbrowser,我'没有经过身份验证。因为我不想登录我创建的每一个 tWebbrowser,所以我想找到一种方法,当我手动打开 IE 的新实例时,如何保持这种身份验证正常工作。目的是从我登录的不同页面获取 HTML。

我想要

1) 从使用 ShellExecute 打开的 Internet Explorer 实例中获取 HTML

或者

2) 让 tWebbrowser 记住来自所有其他打开的 IE 实例的身份验证

或者

3) 将 tWebbrowser 连接到 Internet Explorer 的现有实例

或者

4) 从 Delphi 获取 HTML 的其他方法

身份验证我不知道如何自动化,因为它是 java/sso。

4

1 回答 1

1

您可以通过执行以下操作来查询 IE 窗口的 Windows shell:

uses ShDocVw_Tlb; // or ShDocVw

if Doc = Nil then
  exit;
if Doc.body = Nil then
  exit;

var
  i: Integer;
  Browser: IWebBrowser2;
  ShellWindows: IShellWindows;
  Doc : IHtmlDocument2;

ShellWindows := CoShellWindows.Create;
for i := 0 to ShellWindows.Count - 1 do
  if Supports(ShellWindows.Item(i), IWebBrowser2, Browser) then 
  begin
    // do something with Browser instance, e.g compare the Url you're
    // expecting with Browser.LocationUrl
    // if it is, then you can get at the Html by something like

    Browser.Document.QueryInterface(IHtmlDocument2, Doc);
    if (Doc <> Nil) and (Doc.Body <> Nil) then  
    // access any of the Doc's properties, e.g. InnerHtml

  end;

显然,当 Support 返回 true 时,您可以检查返回的浏览器以查找您要查找的内容。例如,您可以使用IHtmlDocument2浏览器 Document 的界面(首先检查它是否不是 Nil)来访问其 DOM、HTML 等。我想TWebBrowser如果您想要这样做,找到一个窗口相对简单。

于 2013-10-12T15:25:27.260 回答