• 如何获取本地html文件的标题


    本文用于提取本地网页的标签元素如<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;


    文章整理:西部数码--专业提供域名注册虚拟主机服务
    http://www.west263.com
    以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

  • 相关阅读:
    SGU 271 Book Pile (双端队列)
    POJ 3110 Jenny's First Exam (贪心)
    HDU 4310 Hero (贪心)
    ZOJ 2132 The Most Frequent Number (贪心)
    POJ 3388 Japanese Puzzle (二分)
    UVaLive 4628 Jack's socks (贪心)
    POJ 2433 Landscaping (贪心)
    CodeForces 946D Timetable (DP)
    Android Studio教程从入门到精通
    Android Tips – 填坑手册
  • 原文地址:https://www.cnblogs.com/findumars/p/5374956.html
Copyright © 2020-2023  润新知