Delphi7的HtmlParser使用方法

uses
HtmlParser procedure TForm4.Button1Click(Sender: TObject);
var FNodes:IHtmlElement;
aString:string;
begin
FNodes := parserHtml(Memo1.Text);
aString:= FNodes.Children[2].Children[1].Children[5].Children[0].InnerText;
end;
//判断某子结点是否存在,增加代码的可靠性
//if NodeIsExist(FNodes,
//'Children[2].Children[3].Children[11].Children[3].Children[1].Children[1].Children[1].Children[0]'
//) then
//Memo3.Lines.Add(
//FNodes.Children[2].Children[3].Children[11].Children[3].Children[1].Children[1].Children[1].Children[0].InnerText
// );
function NodeIsExist(Root:IHtmlElement;Childrens:string):Boolean ;
var aStringlist:tStringlist; i,aIndex:integer;
aNode:IHtmlElement; aStr:string;
begin
Result:= False;
aStringlist:=TStringList.Create;
aStringlist.Delimiter := '.';
aStringlist.DelimitedText := Childrens; aNode:=Root;
for i := to aStringlist.Count- do begin
aStr:=Copy(aStringlist[i],,Length(aStringlist[i])-);
aIndex:= StrToIntDef(aStr,);
if aIndex>= aNode.ChildrenCount then begin
aStringlist.Free;
Exit;
end;
aNode:=aNode.Children[aIndex];
end;
aStringlist.Free;
Result:= true;
end;
//NodeIsExist的优化版,更高速,只处理最大结点0~99
function NodeIsExist(Root:IHtmlElement;Childrens:string):Boolean ;
VAR i:integer;
aNode:IHtmlElement;
begin
Result:= False;
aNode:=Root;
for i:= to Length(Childrens) do begin //aString[1]从1开始,而不是从零开始
if Childrens[i]=# then begin // ']'
if Childrens[i-]=# then begin // '['
if StrToIntDef(Copy(Childrens,i-,),)>= aNode.ChildrenCount then Exit; //一位数
aNode:=aNode.Children[StrToIntDef(Copy(Childrens,i-,),)];
end;
if Childrens[i-]=# then begin // '['
if StrToIntDef(Copy(Childrens,i-,),)>= aNode.ChildrenCount then Exit; //二位数
aNode:=aNode.Children[StrToIntDef(Copy(Childrens,i-,),)];
end;
end; end;
Result:= true;
end;
Delphi7的HtmlParser使用方法的更多相关文章
- python模块介绍- HTMLParser 简单的HTML和XHTML解析器
python模块介绍- HTMLParser 简单的HTML和XHTML解析器 2013-09-11 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq ...
- python模块使用案例
python模块使用案例 一.使用MySQLdb模块代码示例: # 导入 MySQLdb模块 import MySQLdb # 和服务器建立链接,host是服务器ip,我的MySQL数据库搭建在本机, ...
- python 爬虫部分解释
example:self.file = www.baidu.com存有baidu站的index.html def parseAndGetLinks(self): # parse HTML, save ...
- Python 网络爬虫程序详解
#!/usr/bin/python #调用python from sys import argv #导入sys是导入python解释器和他环境相关的参数 from os import makedirs ...
- python中的__init__(self)是什么意思呢
python中的__init__(self)是什么意思呢 init(self)这个时类的初始化函数 1 2 3 4 class Obj: def init(self): print 1 obj = O ...
- javaSE27天复习总结
JAVA学习总结 2 第一天 2 1:计算机概述(了解) 2 (1)计算机 2 (2)计算机硬件 2 (3)计算机软件 2 (4)软件开发(理解) 2 (5) ...
- Python抓取页面中超链接(URL)的三中方法比较(HTMLParser、pyquery、正则表达式) <转>
Python抓取页面中超链接(URL)的3中方法比较(HTMLParser.pyquery.正则表达式) HTMLParser版: #!/usr/bin/python # -*- coding: UT ...
- 在.net中运用HTMLParser解析网页的原理和方法
本文介绍了.net 版的一个HTMLParser网页解析开源类库(Winista.HTMLParser)的功能特性.工作原理和使用方法.对于使用.net进行Web信息提取的开发人员进行了一次HTMLP ...
- 使用ASIHTTPRequest 编译提示找不到"libxml/HTMLparser.h"的解决方法
使用ASIHTTPRequest xcode编译提示找不到"libxml/HTMLparser.h",解决方法如下: 1>.在xcode中左边选中项目的root节点,在中间编 ...
随机推荐
- MyBatis入门(六)---mybatis与spring的整合
一.整合需要 1.1.方法 上一章中的数据 需要spring通过单例方式管理SqlSessionFactory spring和mybatis整合生成代理对象,使用SqlSessionFactory创建 ...
- 【原】iOSCoreAnimation动画系列教程(一):CABasicAnimation【包会】
本文的最新版本已经发布在简书[编程小翁]上,强烈建议到上查看简书,[点击这里跳转]. 在iOS中,图形可分为以下几个层次: 越上层,封装程度越高,动画实现越简洁越简单,但是自由度越低:反之亦然.本文着 ...
- 在xib中添加手势控件后运行可能会出现的错误
如果出现错误: // -[UITapGestureRecognizer superview]: unrecognized selector sent to instance 0x8e407a0 // ...
- 关于移动端click事件绑定的一个细节
click是最常见的点击事件,但是对于移动终端,比如手机,一般都是以touch事件代替的,而click事件在手机也是生效的,只是会有1-2秒左右的延迟,那么当你想要用click而非touch事件的时候 ...
- 强制IE使用最高版本引擎渲染页面,避免默认使用IE7引擎导致的页面布局混乱及其它问题
背景 基于Asp.net MVC的一个Intranet web application, 现象 Application发布到服务器端后,在客户端IE访问页面布局混乱,并有javascript报错 原因 ...
- python sorted
python列表排序 python字典排序 sorted List的元素可以是各种东西,字符串,字典,自己定义的类等. sorted函数用法如下: sorted(data, cmp=None, key ...
- emacs下安装pip
Ubuntu13.10下安装pip的方法 $ sudo apt-get install python-pip python-dev build-essential $ sudo pip inst ...
- Python Tomcat Script(多实例)
之前书写过 Tomcat 单实例的 Python 脚本,本次增加 Tomcat 多实例的操作脚本. 1:准备 安装所需 Python 插件 A方法: pip install argparse B方法: ...
- centos下yum搭建安装linux+apache+mysql+php环境
一.脚本YUM源安装: 1.yum install wget #安装下载工具wget 2.wge ...
- Socket常见错误
一.简介 本文介绍 Socket 连接常见错误. 二.常见错误 1)ECONNABORTED 描述:"software caused connection abort",即&q ...