Delphi获取所有打开的IE窗口的网页源码

procedure  TForm1.Button1Click(Sender: TObject);
var
  ShellWindow: IShellWindows;
  i: Integer;
  spDisp: IDispatch;
  IE1: IWebBrowser2;
begin
  ShellWindow := CoShellWindows.Create;
  for i:=0 to ShellWindow.Count - 1 do
  begin
    spDisp := ShellWindow.Item(i);
    if spDisp <> nil then
    begin
      spDisp.QueryInterface(iWebBrowser2, IE1);
      if IE1 <> nil then
      begin
        if Pos('http://', LowerCase(IE1.LocationURL)) = 1 then
        begin
          Memo1.Lines.Add(IE1.LocationURL);  //获取网址
          Memo1.Lines.Add((IE1.Document as IHtmlDocument2).body.outerHTML);  //获取源码
        end;
      end;
    end;
  end;
end;
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页