Article View: borland.public.cppbuilder.internet.web
Article #381Re: How to get the "real live" HTML source?
From: Enrique
Date: Sat, 16 Dec 2006 13:04
Date: Sat, 16 Dec 2006 13:04
102 lines
4701 bytes
4701 bytes
It seems OK if you know the name of the desired field. But if you want to
get ALL the "DOM Code", like a new HTML source without Javascript and with
all the fields completed?
I think I need help with the code, these interfaces are my karma...
I've "translated" a Delphi Code that builds a Tree of the DOM, but it does
not work, surely is a bad translation:
//*********//
ORIGINAL (DELPHI)
//*********//
the code below (Delphi) recreates the DOM in a TTreeView.
call it like this:
VisualizeDOMTree(rootElement, nil, treeNodes);
////////////////////////////////////////////////////////////////////////////
/
// element: the IHTMLElement for which we build a subtree
// treeNode: the TreeNode under which we hang the subtree
// treeNodes: the Tree we build
////////////////////////////////////////////////////////////////////////////
/
procedure TCGWTForm.VisualizeDOMTree(element:IHTMLElement;
treeNode:TTreeNode;
treeNodes:TTreeNodes);
var
i: Integer;
myTreeNode: TTreeNode;
curElement: IHTMLElement;
childrenElements: IHTMLElementCollection;
begin
myTreeNode:= treeNodes.AddChild(treeNode, element.tagName);
//get the children collection
childrenElements:= element.children as IHTMLElementCollection;
for i:=0 to childrenElements.length-1 do begin //for each sibling
//get a sidling
curElement:= childrenElements.item(i,0) as IHTMLElement;
//build sibling's subtree
VisualizeDOMTree(curElement, myTreeNode, treeNodes);
end;
end;
//******************************
//******************************
//************//
MY (wrong) TRANSLATION
//************//
void
TInternetExplorer::VisualizeDOMTree(/*TComInterface<IHTMLElement>*/IHTMLElement
element, TTreeNode* treeNode, TTreeNodes* treeNodes)
{
int i
TTreeNode* myTreeNode;
IHTMLElement curElement;
IHTMLElementCollection childrenElements;
myTreeNode = treeNodes->AddChild(treeNode, element.tagName);
//get the children collection
childrenElements = (IHTMLElementCollection)element.children;
for (i=0; i<childrenElements.length; ++i) //for each sibling
{
//get a sidling
curElement = (IHTMLElement)childrenElements.item(i,0);
//build sibling's subtree
VisualizeDOMTree(curElement, myTreeNode, treeNodes);
}
}
//*************************************//
Anyway, this code only builds a Tree of the elements...
And how Fotis (the autor of the delphi code) says:
//-----------------------
"Yes, my code produces only a tree of tags.
you also need tag attributes and text.
Getting all the attributes for each tag
is also possible, its simple (<20 lines), but is
based on some more exotic commands.
You gonna need types like IHTMLDOMNode,
IHTMLAttributeCollection, IHTMLDOMAttribute,
IDispatch, some GUIDs like IID_IHTMLAttributeCollection,
IID_IHTMLDOMNode IID_IHTMLDOMAttribute, etc.
The problem is the text inside, before or after tags
which makes the DOM tree parsing procedure
more complex. Using InnerText does not cover
all cases..... Consider this:
<td>hello <b>world</b> and Enrique</td>
you need getAdjacentText of the IHTMLElement2
interface for "hello" and "and Enrique" parts."
//------------------------
and I have no idea how to do that....
I think that if someone has the code, will be helpfull to put it in the
group, many people could have the same problem (now or in the future), and
clearly it will be a great base of reference for another codes.
Thanks !
enrique.
Technical Details
Message-ID:
<4583eee0@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4582e657@newsgroups.borland.com> <4582eb35$1@newsgroups.borland.com> <45831d53@newsgroups.borland.com> <4583480c$1@newsgroups.borland.com> <45834aa4$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,b54437b3b496861e X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Enrique" <enridp@yahoo.com.ar> From: "Enrique" <enridp@yahoo.com.ar> Newsgroups: borland.public.cppbuilder.internet.web References: <4582e657@newsgroups.borland.com> <4582eb35$1@newsgroups.borland.com> <45831d53@newsgroups.borland.com> <4583480c$1@newsgroups.borland.com> <45834aa4$1@newsgroups.borland.com> Subject: Re: How to get the "real live" HTML source? Date: Sat, 16 Dec 2006 10:04:30 -0300 Lines: 104 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 200.43.99.213 Message-ID: <4583eee0@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1166274272 200.43.99.213 (16 Dec 2006 05:04:32 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail