Article View: borland.public.cppbuilder.internet.web
Article #382Re: How to get the "real live" HTML source?
From: Remy Lebeau (TeamB)
Date: Mon, 18 Dec 2006 19:39
Date: Mon, 18 Dec 2006 19:39
97 lines
4153 bytes
4153 bytes
"Enrique" <enridp@yahoo.com.ar> wrote in message
news:4583eee0@newsgroups.borland.com...
> It seems OK if you know the name of the desired field. But if you
> want to get ALL the "DOM Code"
That is what the "all" collection is for - it contains all of the elements
of the page.
> like a new HTML source without Javascript and with all the fields
completed?
There is no way to remove the Javascript through the DOM. The only way to
do that is to not let the browser download the original HTML at all.
Download it yourself manually. Then you can alter it any way you wish, and
then load the altered HTML into the browser for displaying.
But like I said earlier, if the Javascript is generating content of its own,
then you have to actually run the Javascript in order for it to generate the
output that you are looking for. Otherwise, you have to parse the script
code manually and then generate your own output.
> I've "translated" a Delphi Code that builds a Tree of the DOM, but it does
> not work, surely is a bad translation:
VisualizeDOMTree(rootElement, NULL, treeNodes);
#include <mshtml.h>
#include <utilcls.h>
void __fastcall TInternetExplorer::VisualizeDOMTree(IHTMLElement
*element, TTreeNode *treeNode, TTreeNodes *treeNodes)
{
if( !elements || !treeNodes )
return;
TTreeNode *myTreeNode;
WideString tagName;
element->get_tagName(&tagName);
if( treeNode )
myTreeNode = treeNodes->AddChild(treeNode, tagName);
else
myTreeNode = treeNodes->Add(NULL, tagName);
// get the children collection
TComInterface<IDispatch> disp;
element->get_children(&disp);
if( disp )
{
TComInterface<IHTMLElementCollection> childrenElements;
disp->QueryInterface(IID_IHTMLElementCollection,
(LPVOID*)&childrenElements);
disp.Unbind();
if( childrenElements )
{
long count = 0;
childrenElements->get_length(&count);
for(long i = 0; i < count; ++i) // for each sibling
{
// get a sidling
TVariant Item = i;
TVariant Index = 0;
childrenElements->item(Item, Index, &disp);
if( disp )
{
TComInterface<IHTMLElement> curElement;
disp->QueryInterface(IID_IHTMLElement,
(LPVOID*)&curElement);
disp.Unbind();
// build sibling's subtree
if( curElement )
VisualizeDOMTree(curElement, myTreeNode,
treeNodes);
}
}
}
}
}
I suggest you read the MSDN documentation about the DOM interfaces before
you go any further:
Interfaces and Scripting Objects
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/interface.asp
Gambit
Technical Details
Message-ID:
<4586f05a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!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> <4583eee0@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 From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> 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> <4583eee0@newsgroups.borland.com> Subject: Re: How to get the "real live" HTML source? Date: Mon, 18 Dec 2006 11:39:59 -0800 Lines: 99 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.83.34.171 Message-ID: <4586f05a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1166471258 75.83.34.171 (18 Dec 2006 11:47:38 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail