Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help on getting html content from a webpage...

Status
Not open for further replies.

dphe

Programmer
Joined
Jan 15, 2007
Messages
16
Location
US
I have been trying the following code....

#!bin/perl

use IO::Socket;

my $host = 'my $port = 80;
my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp');
$sock or die "no socket :$!";


$H2 = "GET /index.html\r\n";

open(LOG1, "> web_resp.log") || die print "Can't open log$!\n";

# Set socket to be command buffered.

print $sock "$H2";
select($sock); $| = 1;
read($sock, $buf, 500);

# Now we're connected to the server, let's read the host response
print LOG1 "$buf\n";

#Closing the socket

close $sock;
close(LOG1);

But the problem is that the script hangs and does not respond. What might be wrong? The script does not even throw any errors.

Also want to know if I had to send 10 such parallel requests how would I modify the above. The problem is that, sending the request in a loop would immulate only sequential requests being sent. But to send 10 parallel requests what would I have to do?
 
Please do ignore the beginning... #!bin/perl.... since the path tht i would use is a little diff... other than that if you find any other issues.... please do post a reply... thnkx
 
Why oh why would you choose to use IO::Socket? I'm not saying that it's not possible, but you're essentially reinventing the wheel when you take into account there modules out there specifically for accessing and processing web pages.


Read and be wise.

err ... wait. According to Kevin, I'm supposed to imagine you're a Drag Queen in your underwear. Ok... let's give this a try.

Hey baby. There's this ultra suave module called LWP::Simple that will do all that work for you. It's almost like having a real burley man at home to take care of all the chores. All you got to do is invite it into your own computer, and just let it do all the work. Not only will it setup your sockets, it'll clean your pipes too. Huh huh.
 
Thanks Miller, working on that module... but then how will I run 10 such requests parallely?
 
Thnkx... Used the LWP::UserAgent and its working fine..... But then... just wanted to know how to send 10 requests parallely.. as mention earlier...thnkx in advance...
 
Yeah.. am able to do the same with LWP::Parallel::UserAgent. It works fine.. thnkx for all the help...
 
MillerH

This isn't working, is it? I mean, really "it'll clean your pipes, too" (fnaar fnaar).

It's probably best if you stop living a lie and go back to BOfH mode, or it may cause you to be psychologically scarred for life...[smile]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top