Solved

print Location

Posted on 2000-04-12
6
150 Views
Last Modified: 2013-12-25
Can:
print "Location: http://www.where-ever.com\n\n";
be used to write the contents of a web page to a file?

As in, will:
print FILE "Location: http://www.where-ever.com\n\n";  
work??

0
Comment
Question by:flahertd
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2709249
print "Location: http://www.where-ever.com\n\n";

only redirects you to the given web page.

Therefore print FILE "Location: http://www.where-ever.com\n\n";  
WILL NOT write the contents of that page to your file. it will only write the STRING Location: http://www.where-ever.com\n\n" to the file.

To do that you will have to use other PERL modules.

i have exactly such a PERL script with me. if you want the same, let me know & i will post it to this forum.
0
 

Author Comment

by:flahertd
ID: 2709322
maneshr,

Yeah, that'd be great, if you don't mind.

I can increase the points too if you'd like!

0
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
ID: 2709452
sure. here is the script....

this script gets the required page using HTTP protocol. in fact, its a very basic version of your own browser!!!

if the script cant get the web site it shows why with the help of error message.

you might have to change the path to perl and other files as per your system.
==============get_site.pl
#!/usr/local/bin/perl

require LWP;
require URI::URL;

use strict;
use CGI;

my($hdr,$server_response);
my($statement_URL)="http://www.where-ever.com";

my($query)=new CGI;

##  Right now the values are hard-coded
$hdr="";

$server_response=&browse($statement_URL,$hdr);  ##  Fire the URL

print "Content-type: text/html\n\n";

if ($server_response){
  open(FILE,"/tmp/home_page.html") || die $!;
  print FILE $server_response;
  close(FILE);
  print "<B>Got your Website!!</b>\n";
}else{
  print "<B>Sorry! Could not get your Website!!</b><P>\n";
  print "Error is $server_response<br>\n";
}

## This is the main sub routine!!  
sub browse(){
  my($statement_URL,$hdr)=@_;
  my($content_type,$method,$url,$request,$response);
 
  $content_type="application/x-www-form-urlencoded";
  $method="GET";
 
  my($headers)= new HTTP::Headers
  'Content-Type'   =>  $content_type,
  'MIME-Version'   =>  '1.0',
  'Date'           =>  HTTP::Date::time2str(time),
  'Accept'         =>  'text/html';

  my($ua)= new LWP::UserAgent;
  $ua->agent("Mozilla/4.7 [en] (WinNT; U)"); # Define env variable - HTTP_USER_AGENT

  $url= new URI::URL($statement_URL."?".$hdr);
  $request= new HTTP::Request($method, $url, $headers);


  my($response)= $ua->request($request);

  my($reply);

  if ($response->is_success){
    $reply=$response->content;
  }else{
    $reply=$response->error_as_HTML();
  }
  return $reply;
}

================================

Hope that helps
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:flahertd
ID: 2712198
Adjusted points from 25 to 50
0
 

Author Comment

by:flahertd
ID: 2712199
thanks for your help maneshr!
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2712242
most welcome:-)

Glad to know that the script worked for you.

0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

820 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