//获取网页的NODE function GetNodeByName( MYParentIHTMLDOMNode: mshtml.IHTMLDOMNode;NodeNamestr,NameStr,TheValue:string;AllorPart:boolean):mshtml.IHTMLDOMNode; var Mystr:string; MyIHTMLDOMNode : mshtml.IHTMLDOMNode; i,j:integer; MyIHTMLDOMAttribute: mshtml.IHTMLDOMAttribute2 ; begin
for i:=0 to ((MYParentIHTMLDOMNode.childNodes) as mshtml.IHTMLDOMChildrenCollection).length-1 do begin MyIHTMLDOMNode:=(MYParentIHTMLDOMNode.childNodes as mshtml.IHTMLDOMChildrenCollection).item(i) as mshtml.IHTMLDOMNode ; if assigned(GetNodeByName(MyIHTMLDOMNode,NodeNamestr,NameStr,TheValue,AllorPart)) then begin result:=GetNodeByName(MyIHTMLDOMNode,NodeNamestr,NameStr,TheValue,AllorPart); exit; end; if (ansiuppercase(MyIHTMLDOMNode.nodeName)=ansiuppercase(NodeNamestr)) then if assigned(MyIHTMLDOMNode.attributes) then for j :=0 to (MyIHTMLDOMNode.attributes as mshtml.IHTMLAttributeCollection).length-1 do begin MyIHTMLDOMAttribute:=(MyIHTMLDOMNode.attributes as mshtml.IHTMLAttributeCollection) .item(j) as mshtml.IHTMLDOMAttribute2; Mystr:=MyIHTMLDOMAttribute.name; Mystr:=MyIHTMLDOMAttribute.value; if( ansiuppercase(MyIHTMLDOMAttribute.name)=ansiuppercase(NameStr)) and ((ansiuppercase(MyIHTMLDOMAttribute.value)=ansiuppercase(TheValue)) or (ansipos(ansiuppercase(TheValue),ansiuppercase(MyIHTMLDOMAttribute.value))<>0) and AllorPart ) then begin result:=MyIHTMLDOMNode; exit; end; end;
使用下面范例不能得到正确结果 while node<>nil do begin if node.HasChildren then ... if node.getNextSibling<>nil then node:=node.getNextSibling
----------------------------------------------
-
Function ProcessNode(ANode: ICefDomNode):string; var Node1: Node; begin if Assigned(ANode) then begin Node1 := ANode.FirstChild; while Assigned(Node1) do begin if Node1.IsElement then if Node1.GetElementAttribute('id') ='kw' then begin result:=Node1.AsMarkup; exit end; ProcessNode(Node1); Node1 := Node1.NextSibling; end; end; end;
在不使用全局变量的情况下可以这么搞,哈哈 Function ProcessNode(ANode: ICefDomNode;var Theresult:ustring):ustring; var Node1: ICefDomNode; begin result:=''; if Assigned(ANode) then begin Node1 := ANode.FirstChild; while Assigned(Node1) do begin if Node1.IsElement then if Node1.GetElementAttribute('id') ='kw' then begin MyGetTXT:=Node1.AsMarkup; Theresult:=Node1.AsMarkup; result:=MyGetTXT; GetTheNode:=true; exit; end; ProcessNode(Node1,Theresult); Node1 := Node1.NextSibling; end; end; end;
----------------------------------------------
-