易截截图软件、单文件、免安装、纯绿色、仅160KB

使用TWebBrowser组件保存网页为html和mht文件 收藏

使用TWebBrowser组件保存网页为html和mht文件 收藏
一、保存为HTML文件
uses ActiveX;
...
procedure WB_SaveAs_HTML(WB : TWebBrowser; const FileName : string) ;
var
  PersistStream: IPersistStreamInit;
  Stream: IStream;
  FileStream: TFileStream;
begin
  if not Assigned(WB.Document) then
  begin
    ShowMessage('Document not loaded!') ;
    Exit;
  end;
  PersistStream := WB.Document as IPersistStreamInit;
  FileStream := TFileStream.Create(FileName, fmCreate) ;
  try
    Stream := TStreamAdapter.Create(FileStream, soReference) as IStream;
    if Failed(PersistStream.Save(Stream, True)) then ShowMessage('SaveAs HTML fail!') ;
  finally
    FileStream.Free;
  end;
end; (* WB_SaveAs_HTML *)
使用方法:
WebBrowser1.Navigate('http://www.uufax.com') ;
//then save
WB_SaveAs_HTML(WebBrowser1,'c:\WebBrowser1.html') ;
二、另存为MHT单一文件
uses CDO_TLB, ADODB_TLB;
...
procedure WB_SaveAs_MHT(WB: TWebBrowser; FileName: TFileName) ;
var
  Msg: IMessage;
  Conf: IConfiguration;
  Stream: _Stream;
  URL : widestring;
begin
  if not Assigned(WB.Document) then Exit;
  URL := WB.LocationURL;
  Msg := CoMessage.Create;
  Conf := CoConfiguration.Create;
  try
    Msg.Configuration := Conf;
    Msg.CreateMHTMLBody(URL, cdoSuppressAll, '', '') ;
    Stream := Msg.GetStream;
    Stream.SaveToFile(FileName, adSaveCreateOverWrite) ;
  finally
    Msg := nil;
    Conf := nil;
    Stream := nil;
  end;
end; (* WB_SaveAs_MHT *)
使用方法:
//first navigate
WebBrowser1.Navigate('http://www.uufax.com') ;
//then save
WB_SaveAs_MHT(WebBrowser1,'c:\WebBrowser1.mht') ;
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sunstone/archive/2009/11/09/4788743.a


相关文档:

Web开发 第一部分 HTML教程基础(十三)表格布局

前面的课程中,我们学习了表格元素,上节课中,我们通过一本表格来对表单内的组件进行位置的控制,这其实就是一种简单的表格布局。这节课,我们详细来讨论一下使用表格的布局方法。
看如下代码:
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml ......

html中的分页打印

<html>
<head>
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<title>看看</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print ......

HTML Table layout issue Draw a table

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Page</title>
</head>
<body>
<table border="1px">
......

HTML 标记的原义输出 函数


function unhtml($content){
$content=htmlspecialchars($content);
$content=str_replace(chr(13),"<br>",$content);
$content=str_replace(chr(32),"&nbsp;",$content);
return trim($content);
}
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号