Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Generating Webpage dynamically with Perl

Posted on 2004-05-02
11
Medium Priority
?
253 Views
Last Modified: 2013-12-25
I believe this question is really simple.  I am have a Perl CGI file that I read a page through and I need to be able to then print out the html webpage.  I am in essence creating an html frame without frames.  So when you click on a link it passes you through this page and adds some stuff at the top.  I am fine when the page is part of my website and everything is local because I can read the file into an array and then print it out.  The problem is that a couple of the links are on another site so they come in as the full path with http://etc.  
I need to have a way of knowing the url to just print out the html.  Is there a command or a simple way of doing this.
0
Comment
Question by:spoma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 

Author Comment

by:spoma
ID: 10973948
I found LWP::Simple and this seems to do what I needed.  
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10973953
To output the contents of a URL, do:

use LWP::Simple;
getprint('http://www.example.com/page.html');
0
 

Author Comment

by:spoma
ID: 10991951
TinTin
That worked to a degree.  The problems I encountered was that it was including all of the html heading tags.  I am trying to use a component called HTML::Parser and I have it pretty much working but I am trying ot get it not only to print out text but also to print out the <tags>.  here is th sample code from the web i found.  anyone have any ideas how to make this print out tags also.


 use HTML::Parser ();

  sub start_handler
  {
    return if shift ne "title";
    my $self = shift;
    $self->handler(text => sub { print shift }, "dtext");
    $self->handler(end  => sub { shift->eof if shift eq "title"; },
                           "tagname,self");
  }

  my $p = HTML::Parser->new(api_version => 3);
  $p->handler( start => \&start_handler, "tagname,self");
  $p->parse_file(shift || die) || die $!;
  print "\n";
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 48

Expert Comment

by:Tintin
ID: 10992657
Try

use LWP::Simple;
use CGI ':standard';

$page = get("http://www.example.com/page.html");
print escapeHTML($page);
0
 

Author Comment

by:spoma
ID: 10995158
That does not seem to work either.  What I need is that I do a get like what you suggest:

$treeview = get(url);

this will then get the entire contents of this url.  i need to be able to then strip out certain tags such as <html>,<title>asdfsaDF</title>, any meta information, the <head> tags so that my html will be valid.  

I am in essence taking this html and putting it in a table in the center of my webpage.  so i must get rid of all tags that will make it invalid html.  Am I going about this the best way?  The example I give gives me the ability to pull out certain tags but I can not get it to print the tags I want it merely prints the text associated with the tags.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11000090
So you're asking for something different now.  Previously you said you wanted to print out the tags also.

What form is the data in the page you are retreiving?  Is it already in a table, or is is just straight paragraphs?

0
 

Author Comment

by:spoma
ID: 11000443
No.  I am asking for the same thing.  The current code sample I showed you prints out only the text between certain <TAGS>.  I need it to print out the <TAGS> along with it.  So if I have HTML like the following

<html>
<head>
<style>hello</style>
</head>
etc....

And I say to print out between the <head> tags i need it to give me
<style>hello</style>
currently it would give me
hello
0
 

Accepted Solution

by:
gorch earned 200 total points
ID: 11013773
Hi spoma,

as far as I understand your problem you will need something like:

  # Read in the url line-wise as you would read a file.
  foreach $line (<url>) {

    # Check whether you reached your pattern from which you want to start collecting content.
    if ($line =~ /<start-tag-or-pattern>/) {

        # From now on until the end-tag appears do what you want with the content.
        do {
            print"$line";
        } until ($line =~/<end-tag-or-pattern/);

    }

  }

Embedding this peace of code in a loop and making the patterns variable will enable you to fetch various content pieces from whithin the page.

Does this help?

gorch
0
 
LVL 6

Assisted Solution

by:nitinsawhney
nitinsawhney earned 200 total points
ID: 11144700
Hi Spoma,
One more if you want to print the html code rather then allowing browser to render it then try something like this.


do{
    $line =~ s/</&lt;/g;  
    $line =~ s/>/&gt;/g;
    print "$line";
   }until ($line =~/<end-tag-or-pattern/);


--
Nitin
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question