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;

HtmlParser例子

 //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使用方法的更多相关文章

  1. python模块介绍- HTMLParser 简单的HTML和XHTML解析器

    python模块介绍- HTMLParser 简单的HTML和XHTML解析器 2013-09-11 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq ...

  2. python模块使用案例

    python模块使用案例 一.使用MySQLdb模块代码示例: # 导入 MySQLdb模块 import MySQLdb # 和服务器建立链接,host是服务器ip,我的MySQL数据库搭建在本机, ...

  3. python 爬虫部分解释

    example:self.file = www.baidu.com存有baidu站的index.html def parseAndGetLinks(self): # parse HTML, save ...

  4. Python 网络爬虫程序详解

    #!/usr/bin/python #调用python from sys import argv #导入sys是导入python解释器和他环境相关的参数 from os import makedirs ...

  5. python中的__init__(self)是什么意思呢

    python中的__init__(self)是什么意思呢 init(self)这个时类的初始化函数 1 2 3 4 class Obj: def init(self): print 1 obj = O ...

  6. javaSE27天复习总结

    JAVA学习总结    2 第一天    2 1:计算机概述(了解)    2 (1)计算机    2 (2)计算机硬件    2 (3)计算机软件    2 (4)软件开发(理解)    2 (5) ...

  7. Python抓取页面中超链接(URL)的三中方法比较(HTMLParser、pyquery、正则表达式) <转>

    Python抓取页面中超链接(URL)的3中方法比较(HTMLParser.pyquery.正则表达式) HTMLParser版: #!/usr/bin/python # -*- coding: UT ...

  8. 在.net中运用HTMLParser解析网页的原理和方法

    本文介绍了.net 版的一个HTMLParser网页解析开源类库(Winista.HTMLParser)的功能特性.工作原理和使用方法.对于使用.net进行Web信息提取的开发人员进行了一次HTMLP ...

  9. 使用ASIHTTPRequest 编译提示找不到"libxml/HTMLparser.h"的解决方法

    使用ASIHTTPRequest xcode编译提示找不到"libxml/HTMLparser.h",解决方法如下: 1>.在xcode中左边选中项目的root节点,在中间编 ...

随机推荐

  1. Engine中如何实现先居中显示要素再闪烁

    [解决办法]:需要在要素居中显示之后.闪烁之前执行IScreenDisplay.UpdateWindow强制全刷,如: //居中显示要素 IActiveView actView = axMapCont ...

  2. Python基础(9)--正则表达式

    正则表达式是一个很有用的工具,可处理复杂的字符匹配和替换工作.在Python中内置了一个re模块以支持正则表达式. 正则表达式有两种基本的操作,分别是匹配和替换. 匹配就是在一个文本字符串中搜索匹配一 ...

  3. Oracle行列转换

    一.建表与插入数据 1.1.建表 create table kecheng ( id NUMBER, name ), course ), score NUMBER ); insert into kec ...

  4. C# 文件操作(上传,下载,读取,写入)

    1. 通过byte[]数据下载文件(这种方法可用于以开放Api的形式传递文件内容) public void FileDownLoadByByte(byte[] fileData, string fil ...

  5. cocos2d-x图层以及显示对象的基本使用

    LogoNode: #ifndef LogoNode_hpp #define LogoNode_hpp #include <stdio.h> #include "cocos2d. ...

  6. linux下开启SSH,并且允许root用户远程登录,允许无密码登录

    参考:http://blog.csdn.net/jia0511/article/details/8237698 1. 允许root用户远程登录 修改ssh服务配置文件 sudo vi /etc/ssh ...

  7. 运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory

    运行编译后的程序报错  error while loading shared libraries: lib*.so: cannot open shared object file: No such f ...

  8. hdu 4607 Park Visit 求树的直径

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4607 题目大意:给你n个点,n-1条边,将图连成一棵生成树,问你从任意点为起点,走k(k<=n) ...

  9. 开启mysql慢查询

    Linux查看mysql 安装路径一.查看文件安装路径由于软件安装的地方不止一个地方,所有先说查看文件安装的所有路径(地址).这里以mysql为例.比如说我安装了mysql,但是不知道文件都安装在哪些 ...

  10. Linux下集群的搭建

    1.集群的简介: 集群(cluster)技术是一种较新的技术,通过集群技术,可以在付出较低成本的情况下获得在性能.可靠性.灵活性方面的相对较高的收益,其任务调度则是集群系统中的核心技术. 如果一个事情 ...