用zbird说的TIdHTTP经常会请求不到网页.还是用WebBrowser可靠一些.给你看下例子.如下.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Memo1: TMemo;
procedure WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
var
HtmlCode: String;
begin
if (pdisp as IWebBrowser2).Document = WebBrowser1.Document then //初始化成功后执行
begin
Memo1.text := WebBrowser1.oleobject.Document.Body.InnerHTML; //获取网页html源码
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.niudun.net'); //载入http://www.niudun.net
end;
end.