Welcome, guest | Sign In | My Account | Store | Cart

This recipe shows how you can get perl to do the dirty work. You might also consider looking at the urllib module.

Python, 6 lines
1
2
3
4
5
6
import perl
perl.require("LWP::Simple")
get = perl.get_ref("LWP::Simple::get")

doc = get("http://www.python.org")
print doc

4 comments

Olivier Dagenais 23 years ago  # | flag

Isn't this the "Python" cookbook??? If I wanted to use Perl... Olivier Dagenais

Noah Spurrier 21 years, 6 months ago  # | flag

What was the point? Was the point to demonstrate the perl module? Otherwise, it's easier to do this without the perl.

import urllib

uf = urllib.urlopen ('http://www.python.org')

doc = uf.read()

print doc

Abhineshwar Tomar 15 years, 3 months ago  # | flag

correct working code(py v3.0) for the same would be like this:

import urllib.request

uh = urllib.request.urlopen('http:\\python.org')

h_source = uh.read()

print(html) #this will print souce of the page on stdout
Abhineshwar Tomar 15 years, 3 months ago  # | flag

a correction uh = urllib.request.urlopen('http://python.org')

Created by Gisle Aas on Fri, 23 Feb 2001 (PSF)
Python recipes (4591)
Gisle Aas's recipes (3)

Required Modules

Other Information and Tasks