Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reading a web page into my CGI program

Posted on 1999-07-29
5
Medium Priority
?
230 Views
Last Modified: 2010-03-04
I once saw code to read a page at a URL into my CGI program. It was really short and simple and didn't involve loads of mucking around with sockets.

Any ideas?
0
Comment
Question by:rafistern
[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
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
prakashk021799 earned 600 total points
ID: 1214472
use LWP::Simple;

$page = get("http://www.somewhere.com");
0
 
LVL 5

Expert Comment

by:prakashk021799
ID: 1214473
The above solution is the best one if you just want to get the contents of a web page into your program.

If you want to get into more complicated things, like examining the response code or headers etc., you need to use LWP::UserAgent, which gives you more control.

An example:

use LWP::UserAgent;

$ua = LWP::UserAgent->new;
$request = HTTP::Request->new('GET', 'http://www.somewhere.com');
$response = $ua->request($request);

if ($response->is_success) {
    $page = $response->content;
} else {
    print $response->error_as_HTML;
}
0
 
LVL 4

Author Comment

by:rafistern
ID: 1214474
Your answer looks like it ought to work. However I can't seem to get it working, probably because I am working in an ASP environment using ActiveState Perl (when I said "CGI program", I was not being entirely accurate). I am going to have a go at making it work and in any case I will give you points. However I don't want to close the question right now in order that other people might comment.

Thanks,
Rafi
0
 
LVL 5

Expert Comment

by:prakashk021799
ID: 1214475
ASP and CGI are mutually exclusive. A web server can support both ASP and CGI at the same time.

Also, the above has nothing in it that restricts its use only in a CGI environment. It will work in a CGI script, a normal script or an ASP script (I don't know if such a thing as 'ASP script' exists or not; I am not that well versed with the ASP terminology).
0
 
LVL 4

Author Comment

by:rafistern
ID: 1214476
Yes, I do know the difference between an ASP environment and an executable program or an interpretted script.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

670 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