boeingdream has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I would like to visit a web page, get its http response, and print it. I tried following code, but it's always timeout.
#! /usr/perl/bin use warnings; use strict; use LWP::Simple; my $page_content = get("http://hq.sinajs.cn/list=sh601006"); unless (defined $page_content) { die "doc content is not undef\n"; } print $page_content,"\n";
Besides, I found that, in LWP::Simple, the function _trivial_http_get() cannot build socket connection to target website and return with undef every time.
my $sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Timeout => 30) || return undef;
$port is 80 by default.
Thank you very much for your time.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to visit a web page and print its response?
by wfsp (Abbot) on Sep 14, 2011 at 09:48 UTC | |
by boeingdream (Novice) on Sep 15, 2011 at 01:13 UTC | |
Re: How to visit a web page and print its response?
by zentara (Archbishop) on Sep 14, 2011 at 09:49 UTC | |
by boeingdream (Novice) on Sep 15, 2011 at 01:24 UTC |
Back to
Seekers of Perl Wisdom