使用方法,開啟專案,加入一個TWebBrowser TButton TMemo,然後貼上下列程式碼,之後在元件TWebBrowser事件WebBrowser1DocumentComplete 及 TButton元件上點兩下即可。 IHTMLDocument2此元件為mshtml;
unit readhtmleasy;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, OleCtrls, SHDocVw, mshtml, Grids, ComCtrls, StrUtils,activex;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
slTemp: TStringList;
HTMLDoc: IHTMLDocument2;
begin
Cursor := crHourGlass;
webbrowser1.Navigate('http://www.stockq.org');
HTMLDoc := webbrowser1.Document as IHTMLDocument2;
while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages;
Cursor := crDefault;
HTMLDoc := webbrowser1.Document as IHTMLDocument2;
slTemp := TStringList.Create;
slTemp.text := HTMLDoc.body.innertext;
memo1.text := slTemp.text;
end;
end.
沒有留言:
張貼留言