Newbie LWP Question

B

Bumble

Hi all, trying to develop a program for my Uni project, it is given part of
the address from a form and then it should go to that address and retrieve
the page, now I only want a section of that page, so I'm wondering where I
could do that? Would I need to put it into a text file and then find the
required text from there, or can I manipulate a variable already used to
extract just the text I need? Sorry, just having a bit of trouble getting my
head around the code...

#!/usr/bin/perl -w
use CGI ':standard';
require LWP::UserAgent;

$ua = LWP::UserAgent->new;

$thisisit=param('thisisitinput');

$request = HTTP::Request->new('GET', 'http://www.whatever.com/$thisisit');

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

print ("<html><body bgcolor\"white\">");
print ("<p>$locate</p>");

print ("</body> </html>");

--
Bumble
The 18th 'Biggest Gay on Usenet'
http://bumble.rumble.at


"Your heart felt good it was drippin' pitch and made of wood, and your hands
and knees felt cold and wet on the grass to me. Outside naked, shiverin'
looking blue, from the cold sunlight that's reflected off the moon. Baby cum
angels fly around you reminding you we used to be three and not just two.
And that's how the world began. And that's how the world will end."
 
B

Bumble

Sherm said:
Either approach could be used to give you the end result you're
looking for. So the real question isn't "which do I have to do," but
"which is best for my situation?"

In the simplest case, where you're retrieving the full text every
time, storing it to a file and reading the file back in is a waste of
disk i/o and space.

However, if the page you're retrieving rarely changes, then fetching
it every time you need it is a waste of network bandwidth. You could
get better results in this case by first doing a minimal HTTP "HEAD"
request to get the modification time, and only doing the full "GET"
request if the locally-cached copy of the file needs to be refreshed.

sherm--

Okay, thanks. And now for a really dumbass question, where is the retrieved
html? I'm guessing it's in the $response? But when I've tried to get it to
print $response to the screen it's not doing anything?

--
Bumble
The 18th 'Biggest Gay on Usenet'
http://bumble.rumble.at


"Your heart felt good it was drippin' pitch and made of wood, and your
hands and knees felt cold and wet on the grass to me. Outside naked,
shiverin' looking blue, from the cold sunlight that's reflected off the
moon. Baby cum angels fly around you reminding you we used to be three
and not just two. And that's how the world began. And that's how the
world will end."
 
S

Sherm Pendley

Okay, thanks. And now for a really dumbass question, where is the retrieved
html? I'm guessing it's in the $response? But when I've tried to get it to
print $response to the screen it's not doing anything?

$response is an object - along with the retrieved html, it has the HTTP
status, among other things. So, for example, you could do this:

if ($response->is_success) {
print $response->content;
} else {
print "Error: " . $response->status_line . "\n";
}

You might want to also have a look at the 'lwpcook' perldoc page - lots of
interesting examples there.

sherm--
 
B

Bumble

Sherm said:
$response is an object - along with the retrieved html, it has the
HTTP status, among other things. So, for example, you could do this:

if ($response->is_success) {
print $response->content;
} else {
print "Error: " . $response->status_line . "\n";
}

You might want to also have a look at the 'lwpcook' perldoc page -
lots of interesting examples there.

sherm--

Thanks all!

--
Bumble
The 18th 'Biggest Gay on Usenet'
http://bumble.rumble.at


"Your heart felt good it was drippin' pitch and made of wood, and your
hands and knees felt cold and wet on the grass to me. Outside naked,
shiverin' looking blue, from the cold sunlight that's reflected off the
moon. Baby cum angels fly around you reminding you we used to be three
and not just two. And that's how the world began. And that's how the
world will end."
 
B

Bumble

Having further problems with the below, I'm getting a 'Error: 500 Can't
connect...' when running it from the server, however when I run it from my
own PC it seems to be working? I'm unsure why it would work on my PC from
the command prompt but why it won't retrieve a HTML page when it's on the
server?

TIA
Hi all, trying to develop a program for my Uni project, it is given
part of the address from a form and then it should go to that address
and retrieve the page, now I only want a section of that page, so I'm
wondering where I could do that? Would I need to put it into a text
file and then find the required text from there, or can I manipulate
a variable already used to extract just the text I need? Sorry, just
having a bit of trouble getting my head around the code...

#!/usr/bin/perl -w
use CGI ':standard';
require LWP::UserAgent;

$ua = LWP::UserAgent->new;

$thisisit=param('thisisitinput');

$request = HTTP::Request->new('GET',
'http://www.whatever.com/$thisisit');

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

print ("<html><body bgcolor\"white\">");
print ("<p>$locate</p>");

print ("</body> </html>");



--
Bumble
The 18th 'Biggest Gay on Usenet'
http://bumble.rumble.at


"Your heart felt good it was drippin' pitch and made of wood, and your
hands and knees felt cold and wet on the grass to me. Outside naked,
shiverin' looking blue, from the cold sunlight that's reflected off the
moon. Baby cum angels fly around you reminding you we used to be three
and not just two. And that's how the world began. And that's how the
world will end."
 
S

Sherm Pendley

Having further problems with the below, I'm getting a 'Error: 500 Can't
connect...' when running it from the server, however when I run it from my
own PC it seems to be working? I'm unsure why it would work on my PC from
the command prompt but why it won't retrieve a HTML page when it's on the
server?

Sounds like outbound connections from the web server may be blocked at the
firewall. This is often done to help prevent the spread of viruses - if
the web server is infected somehow, the firewall will prevent the virus
from connecting to other servers to propagate itself.

Ask your system admin about it.

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top