Z
zs174
Unregistered / Unconfirmed
GUEST, unregistred user!
我需要打开一个网页就保存到预先设定的路径,最好有源代码。
请发给我:zs174@163.com谢谢.
请发给我:zs174@163.com谢谢.
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.263.net');
end;
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
var oleComObject:IOleCommandTarget;
vIn,Vout:oleVariant;
begin
WebBrowser1.Document.QueryInterface(IOleCOmmandTarget,oleComObject);
try
oleComObject.Exec(nil,OLECMDID_SAVEAS,OLECMDEXECOPT_DODEFAULT,vIn,vOut);
finally
oleComobject._Release;
end;
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls,ActiveX;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1:TWebBrowser;
procedure WebBrowser1DownloadComplete(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
var oleComObject:IOleCommandTarget;
vIn,Vout:oleVariant;
begin
WebBrowser1.Document.QueryInterface(IOleCOmmandTarget,oleComObject);
try
oleComObject.Exec(nil,OLECMDID_SAVEAS,OLECMDEXECOPT_DODEFAULT,vIn,vOut);
finally
oleComobject._Release;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.263.net');
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls,ActiveX;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1:TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.263.net');
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
PersistFile:IPersistFile;
begin
PersistFile:=WebBrowser1.Document as IPersistFile;
PersistFile.Save(StringToOleStr('c:/k.htm'), system.True);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls,ActiveX, mshtml;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1:TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.263.net');
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
PersistFile:IPersistFile;
Doc:IHTMLDocument2;
begin
PersistFile:=WebBrowser1.Document as IPersistFile;
Doc:=WebBrowser1.Document as IHTMLDocument2;
PersistFile.Save(StringToOleStr('c:/'+Doc.title+'.html'), system.True);//如果你硬要是保存url,就写成:
//PersistFile.Save(StringToOleStr('c:/'+Doc.url), system.True);不过URL里面会有些不能用在文件名中的字符,你要么是替换,要么
//自己在写程序处理。比如"/",你就建一个子目录等等。
end;