网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 手机学院 | 邮件系统 | 网络安全 | 认证考试
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Delphi教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.枚舉並設置界面的Caption之多語言.
.屏蔽“任务管理器”.
.如何实现API钩子.
.Delphi数据库编程教程(五).
.增强MIDAS的安全性.
.三谈多态——善用virtual.
.Delphi与Word(三)取得Word文件.
.利用Delphi编写Windows外壳扩展.
.DesignPattern之FactoryMethod.
.计算出用字符串表示的数学表达式.
.一个设置任意窗口透明度的命令行.
.Delphi异常处理的基本原则和方法.
.为应用软件加入全面的功能权限控.
.DELPHI中的快捷方式一览(完全正式.
.DELPHI中动态调用dll.
.DBGrid中用光标键控制Cell.
.在DELPHI中用线程排序.
.制作一个简单的setup.
.Delphi中的线程类--之(3).
.delphi7从入门到精通之三.

如何获取本地HTML文件的标题,超级链接

发表日期:2006-2-4

本文用于提取本地网页的标签元素如<TITLE></TITLE>,<IMG>,<A></A>...的内容,非常实用于批量文件的操作,这是按一般文件进行文本查找替换无法比拟的,,而这是使用TWEBBROWSER控件无法做到的。类似的,
你可以把本地的HTML文件转换成MHT文件(这是个大家觉得很棘手的问题,本人已经搞定)。

//uses activex,mshtml

function Html_GetTitleFromFile(const HtmlFile:TFileName;var FileTitle:String):Boolean;
var
Idoc     : IHtmlDocument2;
//ElementGroup : IhtmlElementCollection;
//HtmlItem: IHTMLElement;
PersistFile: IPersistFile;
begin
Result:=False;
if not fileexists(HtmlFile) then
exit;
  FileTitle:='';

  try
       Idoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
       PersistFile := IDoc as IPersistFile;
       if PersistFile.Load(StringToOleStr(HTMLFile),1)<>S_OK then
       exit;
       IDoc.designMode := 'on';  //This will disable script execution.
    {   while IDoc.readyState <> 'complete' do  //if it dead here,how to do it?
       begin
       application.ProcessMessages;
       end;
    }
    //   Showmessage(IDoc.readyState);
       Application.ProcessMessages;
       sleep(1000);
    //   Showmessage(IDoc.readyState);
       if IDoc.readyState<>'complete' then
       begin
       Application.ProcessMessages;
       sleep(1000);
       end;
       if IDoc.readyState<>'complete' then
       begin
       IDoc:=nil;
       Result:=False;
       exit;
       end;
        Result:=True;
       FileTitle:=IDoc.title;
       {  //This code also works
       ElementGroup:=IDoc.all.tags('TITLE') As IhtmlElementCollection;
       HtmlItem:=ElementGroup.item(0,0) As IHtmlElement;
       FileTitle:=HtmlItem.innerText;
       }

   finally
        IDoc := nil;
   end;
end;


上一篇:Delphi命令行参数 人气:11869
下一篇:BPCS系统现金流量分析工具开发日志 人气:12179
浏览全部Delphi的内容 Dreamweaver插件下载 网页广告代码 2009年新年快乐