Article View: borland.public.cppbuilder.internet.web
Article #168Re: Extracting all the HTMLElements from IHTMLDocument2
From: Remy Lebeau (TeamB)
Date: Mon, 24 Sep 2007 17:46
Date: Mon, 24 Sep 2007 17:46
64 lines
3234 bytes
3234 bytes
"Van" <suskovivor@yahoo.com> wrote in message
news:46f7e838$1@newsgroups.borland.com...
> how can i filter out all the IFRAMEs in the webpage?
You already are. The frames collection of IHTMLDocument2 can contain either
<frame> or <iframe> objects, depending on whether the containing document is
using a <frameset> or <body> tag, respectively.
> // van's note
> if(!bp->Busy && bp->Document &&
> AnsiString(bp->LocationURL) != "about:blank" &&
> SUCCEEDED(bp->Document->QueryInterface(
> IID_IHTMLDocument2, (LPVOID*)&HTMLDoc)))
That is not the correct way to handle the document. The Busy property is
misleading. Use the ReadyState property instead:
if( (bp->ReadyState == READYSTATE_COMPLETE) && (bp->Document) &&
SUCCEEDED(bp->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&HTMLDoc)) )
Otherwise, you can access the IHTMLDocument2 interface before the document
has been fully loaded. Also, keep in mind that frames have their own
IHTMLDocument2 interface as well, so you have to wait for the secondary
pages to finish loading before their links can be accessed.
> VARIANT out;
You are not initializing that VARIANT, and you are not call VariantClear()
to release the IDispatch interface after you finish using it.
> pColl->item(&one,&out);
You are not checking to make sure that the call succeeds before using the
contents it returns.
> If we get an IFRAME, how can we get the links generated by the IFRAME
script?
If the links are being written to the page, and thus are part of the
document's DOM collection, then you should have no trouble accessing them
the way you already are.
> VARIANT two = {0};
That is not the correct way to initialize a VARIANT. You need to use
VariantInit() instead.
> pColl->item(one,two,&id);
Again, you are not releasing the returned IDispatch interface after you are
finished using it.
> From my POV, this code will always assign res = NULL when try to get
> an HTMLDocument2 from an IFRAME:
Only if the IFRAME is not fully loaded yet at the time you try to access its
Document. Which is a possibility since none of your code is waiting for
windows to finish loading themselves before access their documents.
Gambit
Technical Details
Message-ID:
<46f7f81a@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<46c061ea$1@newsgroups.borland.com> <46c09536@newsgroups.borland.com> <46f7e838$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,26c174002c4041d7 X-Google-Attributes: gidfeeec,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <46c061ea$1@newsgroups.borland.com> <46c09536@newsgroups.borland.com> <46f7e838$1@newsgroups.borland.com> Subject: Re: Extracting all the HTMLElements from IHTMLDocument2 Date: Mon, 24 Sep 2007 10:46:27 -0700 Lines: 66 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.29.61 Message-ID: <46f7f81a@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1190656026 75.83.29.61 (24 Sep 2007 10:47:06 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail