Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How to visit a web page and print its response?

by boeingdream (Novice)
on Sep 14, 2011 at 09:05 UTC ( #925843=perlquestion: print w/ replies, xml ) Need Help??
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.

Comment on How to visit a web page and print its response?
Select or Download Code
Re: How to visit a web page and print its response?
by wfsp (Abbot) on Sep 14, 2011 at 09:48 UTC
    I got
    var hq_str_sh601006="??????,7.37,7.34,7.42,7.43,7.29,7.40,7.43,176707 +75,129752670,28317,7.40,13000,7.39,57549,7.38,126200,7.37,70300,7.36, +655502,7.43,130600,7.44,268071,7.45,37000,7.46,12500,7.47,2011-09-14, +15:03:05";
    Is that something like you were expecting?
      Yes, that's it. I have no idea if it work against my system firewall.
Re: How to visit a web page and print its response?
by zentara (Archbishop) on Sep 14, 2011 at 09:49 UTC
    Your code works here, for me, on linux. Maybe you have a firewall ( or similar) problem?

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Thanks, my Windows firewall is turned off, but my Synmantec control cannot be accessed, due to maybe some company policy. Any way, thank you and wfsp again.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://925843]
Approved by Corion
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-07-11 01:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (217 votes), past polls