网站导航免费论文 原创论文 论文搜索 作业答案 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 交易代码 > Delphi精品代码 > 正文
如何获取本地HTML文件的标题,超级链接
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 10/11/07

 本文用于提取本地网页的标签元素如<T I  T L E><  / T  I  T  L  E>,<I  M  G>,<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;

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 电话:013574892963 QQ:3710167 邮箱:Educs@163.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 Www.myeducs.Cn All Rights Reserved
湘ICP备09003080号