Ovid has asked for the wisdom of the Perl Monks concerning the following question:

While creating a Web content management system, I created some sample plugins to test out what I had built. One of them would get the HTML from another site and stick everything between the body tags into the current document. It's kind of like having frames without the headache of frames. This wasn't intended to be anything fancy and I knew it would break many things such as JavaScript, images with relative links, etc. The owner of the company, however, was so excited and wants me to develop this into something truly useful. Here's what I have so far (somewhat simplified).

package Onsite::Template::Plugin::Mirror; use strict; use warnings; use HTML::TokeParser::Simple; BEGIN { require LWP::Simple; } use base qw/Onsite::Template::Plugin::Base/; sub run { my $self = shift; my $site = $self->get_site; my $html = LWP::Simple::get( $site ); my $output = ''; if ( ! $html ) { $output = "<strong>Could not retrieve Web page for '$site'</st +rong>"; } else { my $p = HTML::TokeParser::Simple->new( \$html ); my $token; do { $token = $p->get_token } until $token->is_start_tag('body +'); do { $token = $p->get_token; last if ! $token; # just in case someone forgets a closing + body tag $output .= $token->return_text; } until $token->is_end_tag('body'); } return $output; }

Note: this runs through Template Toolkit as a plugin.

For the end user, this is as simple as using a URL similar to the following.

http://somesite.com/mod_perl/index.cgi?page=3&site=http://some_target. +com

Since I need to try actually turn this into something serious and emulate frames without actually using them, here are the issues that have crossed my mind.

I'm not terribly worried about Javascript or bad HTML as the only sites that we would target would be sites that we create. However, I'm concerned about what else I might be missing. If there are many hyperlinks, creating an MD5 has for every one could be time consuming, even under mod_perl. Since I've not tried to do something like this before, I'd love to see some suggestions on things I might trip up on, or anything that I may have overlooked.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: Frames without frames
by PodMaster (Abbot) on Aug 24, 2002 at 02:53 UTC
    *grin*

    Take a look at HTML::LinkExtractor, for a nice comprehensive list of URL/Link's. Now this may not be an issue, but it's nice to have a complete list.

    Have you thought about creating a table out of a frameset?

    I suggest DB_File for easy caching ;)

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Frames without frames
by valdez (Monsignor) on Aug 24, 2002 at 00:06 UTC

    I tried adding a <BASE HREF="..."> just after <HEAD> tag and it seems to work with many complex pages. Hope this helps.

    Of course, using BASE forces you to use absolute link in your local page. Some documentation can be found here.

    Ciao, Valerio

    Update: I missed the point: my solution will not work with contents included from different sources...

Re: Frames without frames
by BrowserUk (Patriarch) on Aug 24, 2002 at 08:54 UTC

    You'll need to deal with links in the frame that target="frame_name" other frames in the set, if these are used anywhere.


    What's this about a "crooked mitre"? I'm good at woodwork!