怎么用程序把一个HTML页面保存成一个TXT文件

天轶_1 2005-04-23 03:54:52
如题,就象点IE的“文件-》另存为-》index.txt”一样,当然是用程序实现。
...全文
288 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cutecute 2005-04-30
  • 打赏
  • 举报
回复
easy..
IHTMLDocuemnt2 p = your cocument's IHTMLDocument2 pointer
p.GetDocumentElement.getInnerText() ------ this is what you want.
僵哥 2005-04-30
  • 打赏
  • 举报
回复
这个刚获取到所有当前打的IE窗口里面的html代码。
僵哥 2005-04-30
  • 打赏
  • 举报
回复
Delphi代码倒是有,不过不大想翻译,麻烦不要问为什么
=====================================================
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean;
var
ps: IPersistStreamInit;
s: string;
ss: TStringStream;
sa: IStream;
begin
ps := WB.document as IPersistStreamInit;
s := '';
ss := TStringStream.Create(s);
try
sa:= TStreamAdapter.Create(ss, soReference) as IStream;
Result := Succeeded(ps.Save(sa, Bool(True)));
if Result then ACode.Add(ss.Datastring);
finally
ss.Free;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
ShellWindow: IShellWindows;
WB: IWebbrowser2;
spDisp: IDispatch;
IDoc1: IHTMLDocument2;
k: Integer;
begin
ShellWindow := CoShellWindows.Create;
// get the running instance of Internet Explorer
for k := 0 to ShellWindow.Count do
begin
spDisp := ShellWindow.Item(k);
if spDisp = nil then Continue;
// QueryInterface determines if an interface can be used with an object
spDisp.QueryInterface(iWebBrowser2, WB);
if WB <> nil then
begin
WB.Document.QueryInterface(IHTMLDocument2, iDoc1);
if iDoc1 <> nil then
begin
WB := ShellWindow.Item(k) as IWebbrowser2;
begin
// Add HTML Code to Memo
Memo1.Lines.Add('****************************************');
Memo1.Lines.Add(WB.LocationURL);
Memo1.Lines.Add('****************************************');
GetHTMLCode(WB, Memo1.Lines);
end;
end;
end;
end;
end;


end.
天轶_1 2005-04-24
  • 打赏
  • 举报
回复
我需要的是 leonatcs(LeonKennedy)(每天逛一逛csdn,有益身心健康。) 说的那种形式。不过没有具体代码。谁有?
Builder007 2005-04-24
  • 打赏
  • 举报
回复
用NMHTTP控件查看HTML源代码,再用Memo->Lines->SaveToFlie("*.html");
就OK了
leonatcs 2005-04-24
  • 打赏
  • 举报
回复
TCppWebBrowser的document属性应该可以做到,但是需要COM的知识。
leonatcs 2005-04-23
  • 打赏
  • 举报
回复
分析html文件的内容。
leonatcs 2005-04-23
  • 打赏
  • 举报
回复
不知道有没有这方面的控件,应该是要自己编算法,不是很容易。
至少要懂html的语法,然后就知道哪些是页面上显示出来的文字,
(比如<body></body>之间的字就是)。
然后把这些文字提取出来,
然后存为txt。


天轶_1 2005-04-23
  • 打赏
  • 举报
回复
我的意思是HTML转TXT
flowercity 2005-04-23
  • 打赏
  • 举报
回复
直接修改文件后缀就搞定

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧