zoukankan      html  css  js  c++  java
  • delphi webbroser循环读取网页(来自msdn的判断网页载入完毕的方法)

    源代码如下:

    unit Unit2;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, OleCtrls, SHDocVw;

    type
      TForm2 = class(TForm)
        WebBrowser1: TWebBrowser;
        Button1: TButton;
        ListBox1: TListBox;
        procedure FormShow(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure WebBrowser1DocumentComplete(ASender: TObject;
          const pDisp: IDispatch; var URL: OleVariant);
      *******
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form2: TForm2;
      ok:Boolean;

    implementation

    {$R *.dfm}
    //{$APPTYPE CONSOLE}

    procedure TForm2.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
    //循环读取网站
    for I := 0 to ListBox1.Count-1 do
    begin
      WebBrowser1.Navigate(ListBox1.Items[i]);

      while True do
      begin
        if ok then break;
        Application.ProcessMessages();
      end;
      ok:=false;
    end;

    end;

    procedure TForm2.FormShow(Sender: TObject);
    var
      filename:string;
      myfile:TextFile;
      s:string;
      i:integer;
    begin
    //全局变量初始化
    ok:=false;
    //初始化列表框
    filename:=ExtractFilePath(Application.ExeName)+'\list.txt';
    AssignFile(myfile,filename);
    try
      Reset(myfile);
    except
      on e:Exception do
      begin
        ShowMessage(e.Message);
        Rewrite(myfile);
      end;

    end;
    i:=0;
    while not SeekEof(myfile) do
    begin
      Readln(myfile,s);
      ListBox1.Items.Add(s);
      inc(i);
    end;
    CloseFile(myfile);

    end;

    procedure TForm2.WebBrowser1DocumentComplete(ASender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    begin

      if(pDisp=WebBrowser1.Application) then
      begin
        //Writeln('ok');
        ok:=true;
      end;
    end;

    end.
     

    源代码下载:http://www.rayfile.com/files/264444e1-1488-11df-9b90-0015c55db73d/

  • 相关阅读:
    DataTable的一些使用技巧
    Linux下使用Mysql
    【Cocos2d-X开发学习笔记】第28期:游戏中音乐和音效的使用
    HDU 4669 Mutiples on a circle (DP , 统计)
    面试经典-设计包含min函数的栈
    最大熵模型
    这篇文章关于两阶段提交和Paxos讲的很好
    【读书笔记】神经网络与深度学习
    这个对协程的分析不错
    sendfile学习
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668553.html
Copyright © 2011-2022 走看看