[oclug] access to a website with PERL

Robert Echlin rechlin at magma.ca
Wed Apr 21 13:51:23 EDT 2004


These are nice ideas, guys, but I notice that there is some code, a bit 
like Bob's, on page 349 of "Programming Perl". Maybe he is trying to 
learn sockets in a more general fashion than what CURL etc allow.

It's useful, for learning, to be able to look at the raw text going to 
the TCP socket. I like the UserAgent example, myself.

Robert

Chris Price wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Kevin McCann wrote:
> | Bob Lockie wrote:
> |
> |> I am trying to access a web site with PERL.
> 
> | Hi Bob, have you tried curl? You could call it from within Perl using
> | system() if you need to feed the output to some other process within
> | your script. For example, when going to whatsmyip.com it returns to
> | stdout the HTML including the IP address within H1 tags. Your script
> | could extract the IP address from there.  Unless you just want to figure
> | out the direct Perl connection way as an exercise, in which case you can
> | ignore this.
> 
> Another way to use curl from within a perl script is to open up a file
> handle to it.  For example the following will let you read in the HTML
> of a web page line by line:
> 
> open( INPUT, "curl http://www/google.ca|" ) or die
> ~                                 "curl is not Installed,".
> ~                                 " or no connection to".
> ~                                 " Internet.\n";
> #
> # Read the HTML line by line.
> #
> while( $line = <INPUT> ) {
> ~    #
> ~    # Do what you want here :-)
> ~    #
> }
> 
> close( INPUT );
> 
> LWP::Simple is also a nice way to go, however I like using curl :-)
> 
> Cheers,
> 
> Chris
> 
> - --
> Christopher Price
> Web Applications Consultant
> Tel: (613) 255-0780
> http://www.webapps.ca
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (MingW32)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
> 
> iD8DBQFAhrLyhXcN5z0QOeIRAj1OAJoCdcQOV8pm9ojrmKO18gUwldSkyACeIsJk
> 2JWfivsHDw9bMLQ5eJ3C+1U=
> =YwJt
> -----END PGP SIGNATURE-----

-- 
Robert Echlin
rechlin [at] magma.CA
Personal site: "Some People's Parents" => magma.ca/~rechlin
Company site: OfficeProfessor.CA



More information about the OCLUG mailing list