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. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q57-Q59)

    Question 57You update a solution validator.You need to ensure that all SharePoint solutions are vali ...

  2. IOS中把字符串加密/IOS中怎么样MD5加密/IOS中NSString分类的实现

    看完过后,你会学到: 1学习IOS开发中的分类实现, 2以及类方法的书写, 3以及字符串的MD5加密/解密. ---------------------------wolfhous---------- ...

  3. IOC基础

    Ioc-Inversion of Control,即"控制反转",不是什么技术,而是一种设计思想.在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对象 ...

  4. Java 实现多线程的三种方式

    import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; public class Main { pu ...

  5. iOS开发之保存照片到系统相册(Photo Album)

    iOS开发之保存照片到系统相册(Photo Album) 保存照片到系统相册这个功能很多社交类的APP都有的,今天我们简单讲解一下,如何将图片保存到系统相册(Photo Album). 创建UIIma ...

  6. Cocos2d入门--3--小球运动

    本章直接上源代码.内容不难,主要就是 HelloWorldScene.h文件: #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H_ ...

  7. 关于ajax请求数据后,数据本身的js失效的一些想法

    今天遇到一个头疼的问题.我做一个左右翻页效果(客户要求能够无限翻页),所以只能动态请求数据,进行局部刷新操作. 这时候问题就出来了,当我请求翻页的时候,数据通过js填充到div里面,但这些数据,自身带 ...

  8. 敏捷软件开发:原则、模式与实践——第8章 SRP:单一职责原则

    第8章 SRP:单一职责原则 一个类应该只有一个发生变化的原因. 8.1 定义职责 在SRP中我们把职责定义为变化的原因.如果你想到多于一个的动机去改变一个类,那么这个类就具有多于一个的职责.同时,我 ...

  9. Effective Java 75 Consider using a custom serialized form

    Principle Do not accept the default serialized form without first considering whether it is appropri ...

  10. JavaScript Patterns 2.10 Naming Conventions

    1. Capitalizing Constructors var adam = new Person(); 2. Separating Words camel case - type the word ...