Solved

print Location

Posted on 2000-04-12
6
148 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now