打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
如何获取本地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;


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
恢复htm,html文件图标问题
excel超链接打不开的办法由于本机的限制,该操作已被取消,请与系统管理员联系
java将Word/Excel/PDF文件转换成HTML整理
修复文件图标系统默认关联的最终方法
用Java巧把Word转换成Html文件
xcel2013版本提示“您的组织策略阻止我们为您完成此操作”的解决方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服