您的当前位置:我要购书网>在线阅读>Delphi/Perl

[推荐]--如何获取本地html文件的标题,超级链接。。。?

来源:互联网  作者:我要购书网信息中心  发布:我要购物网收集整理  发布时间:2006-8-31 人气:270

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

//uses activex,mshtml

function Html_GetTitleFromFile(const HtmlFile:TFileName;var FileTitle:String):Boolean;varIdoc : IHtmlDocument2;//ElementGroup : IhtmlElementCollection;//HtmlItem: IHTMLElement;PersistFile: IPersistFile;beginResult:=False;if not fileexists(HtmlFile) thenexit; 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;

相关文章
· [推荐]--如何获取本地html文件的标题,超级链接。。..
· [推荐]windows网络编程经典入门
热点文章
%>
· creating user controls
· 提高fastreplace速度 (fstrrep.pas)
· asc ii 完整码表及简介
· 自动生成拼音(汉字反查到拼音)
· sql2000无法安装的解决办法
· 浏览器集成教学 自定义浏览器
· vc++技术内幕(第四版)笔记(第7章)
· mysql5.0中文乱码解决方案
· sql server日期计算
· vc下利用ado连接access数据库
 淘宝旺旺:我要购书网上书店『图书目录
本购书中心地址: 杭州市延安路111号清波商厦南楼D座(总部) 上海市闸北区老沪太路网上购书中心(沪部),  邮编:310002
电子邮件:books@51goushu.com  经营许可证编号:沪ICP备06038574号
版权所有 2003-2008 © All Rights Reserved .购书网