Re: Question about using Xpath with Frames

From: Chung Le <chung_le_at_dslextreme.com>
Date: Wed, 26 Apr 2006 22:50:45 -0700

David,

It seems to me that in order to process a DOM tree with FRAMEs, one
needs to navigate from the top of the document to get to the appropriate
frame. From there, you can get to its html doc via the contentDocument
attribute. For example, the document I want to process has the following
path:
/document1/html/frameset/frame[2]/document2/html/frameset/frame[1]/document3/html/framese/frame[2]/document4

Breaking it down to three xpaths for the frames, I got:
    /html/frameset/frame[2]
    /html/frameset/frame[1]
    /html/framese/frame[2]

To get document2,
    var xpath = "/html/frameset/frame[2]";
    var frameResult = doc.evaluate(xpath, doc, null,
XPathResult.ANY_UNORDERED_NODE_TYPE,null).singleNodeValue;
    var document2 = frameResult.contentDocument;
It's probably not the most efficient way, but it works.

Cheers,
-- Chung --

David Huynh wrote:

> Chung,
>
> I've downloaded Xpather and couldn't figure out their xpath feature,
> either :-) Let us know if you are successful at contacting Xpather's
> author. I'll let you know if I run into anything relevant.
>
> David
>
>
> Chung Le wrote:
>
>> Hi,
>>
>> I've been successfully writing screen scrapers using Xpath and
>> JavaScript for my PiggyBank application. Recently, I discovered that
>> my scraper doesn't work if the DOM has Frames. I looked at Xpathers
>> which says that Frames are supported. But I couldn't find any
>> documentation about how to use the feature.
>> I would appreciate any help on how to get Xpath to work with Frames.
>> Many thanks.
>>
>> -- Chung --
>
>
>
>
>
Received on Thu Apr 27 2006 - 05:49:25 EDT

This archive was generated by hypermail 2.3.0 : Thu Aug 09 2012 - 16:39:18 EDT