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 := 0 to aStringlist.Count-1 do begin aStr:=Copy(aStringlist[i],10,Length(aStringlist[i])-10); aIndex:= StrToIntDef(aStr,0); 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:=1 to Length(Childrens) do begin //aString[1]从1开始,而不是从零开始 if Childrens[i]=#93 then begin // ']' if Childrens[i-2]=#91 then begin // '[' if StrToIntDef(Copy(Childrens,i-1,1),0)>= aNode.ChildrenCount then Exit; //一位数 aNode:=aNode.Children[StrToIntDef(Copy(Childrens,i-1,1),0)]; end; if Childrens[i-3]=#91 then begin // '[' if StrToIntDef(Copy(Childrens,i-2,2),0)>= aNode.ChildrenCount then Exit; //二位数 aNode:=aNode.Children[StrToIntDef(Copy(Childrens,i-2,2),0)]; end; end; end; Result:= true; end;
总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。
分类:
Delphi7相关
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
2008-12-08 tulater成语词典 chm格式 、EXE格式、网页版