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. Enforcing the correct protocol for partially SSL secured SharePoint sites

    Enforcing the correct protocol for partially SSL secured SharePoint sites http://www.sharepointconfi ...

  2. 简单好用的Toast封装类——EasyToast

    我们用toast时不能设置显示的时间,而且不支持在线程中展示toast,下面我对原始的toast进行了封装,这样我们可以很方便的进行toast的使用了. package com.kale.lib.ut ...

  3. android 判断屏幕是否亮着

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); boolean screen = p ...

  4. 将spring源码导入到eclipse中

    前置条件: 1. 正确安装jdk,并配置好JAVA_HOME.PATH.(我这里安装的是jdk1.8) 2. 正确安装好eclipse.(我的eclipse版本是: Neon Release (4.6 ...

  5. const,static,extern简介(重要)

    一.const与宏的区别(面试题): const简介:之前常用的字符串常量,一般是抽成宏,但是苹果不推荐我们抽成宏,推荐我们使用const常量. 编译时刻:宏是预编译(编译之前处理),const是编译 ...

  6. [转]Designing a User Interface

    UI design can be divided into three essential elements : functionality, aesthetics, and performance. ...

  7. android媒体文件扫描

    项目中可能有这样的需求:下载或导入.导出的图片.音乐等媒体文件,需要马上能在图库或本地视屏播放器中显示出来,或者要能在媒体数据库中查询到媒体文件的相关信息,这时我们就得主动通知系统扫描新的媒体文件了. ...

  8. 读书笔记——Windows环境下32位汇编语言程序设计(6)使用浮点指令进行64位除法

    罗云彬 典藏版Page192,mark下. 这段代码看不懂,手册上根本没有fdivr不带操作数的指令. .data dqTickCounter1 dq ? dqTickCounter2 dq ? dq ...

  9. thumbnailator图片处理

    一.简介 thumbnailator是一个用来对图片对象进行操作的Java类库.通过它我们可以很方面的使用代码的方式,对图片进行一些操作.如缩放,裁减,旋转,水印等.thumbnailator项目主页 ...

  10. QQ JS省市区三级联动

    如下图: 首先写一个静态的页面: <!DOCTYPE html> <html> <head> <title>QQ JS省市区三级联动</title ...