Skip to main content
The 2024 Developer Survey results are live! See the results
added 179 characters in body
Source Link
user3064538
user3064538

In Python 2, use urllib2 which comes with the standard library.Use urllib.request.urlopen():

import urllib2urllib.request
response =with urllib2urllib.request.urlopen('http://www.example.com/') as f:
    html = responsef.read().decode('utf-8')

This is the most basic way to use the library, minus any error handling. YouYou can also do more complex stuff such as changing headers. The documentation can be found

On Python 2, the method is in here.urllib2:

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

In Python 2, use urllib2 which comes with the standard library.

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

This is the most basic way to use the library, minus any error handling. You can also do more complex stuff such as changing headers. The documentation can be found here.

Use urllib.request.urlopen():

import urllib.request
with urllib.request.urlopen('http://www.example.com/') as f:
    html = f.read().decode('utf-8')

This is the most basic way to use the library, minus any error handling. You can also do more complex stuff such as changing headers.

On Python 2, the method is in urllib2:

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

In Python 2, use urllib2 which comes with the standard library.

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

This is the most basic way to use the library, minus any error handling. You can also do more complex stuff such as changing headers. The documentation can be found here.here.

In Python 2, use urllib2 which comes with the standard library.

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

This is the most basic way to use the library, minus any error handling. You can also do more complex stuff such as changing headers. The documentation can be found here.

In Python 2, use urllib2 which comes with the standard library.

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

This is the most basic way to use the library, minus any error handling. You can also do more complex stuff such as changing headers. The documentation can be found here.

added 13 characters in body
Source Link
Aaron Hall
  • 388.6k
  • 91
  • 409
  • 337

UseIn Python 2, use urllib2 which comes with the standard library.

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

This is the most basic way to use the library, minus any error handling. You can also do more complex stuff such as changing headers. The documentation can be found here.

Use urllib2 which comes with the standard library.

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

This is the most basic way to use the library, minus any error handling. You can also do more complex stuff such as changing headers. The documentation can be found here.

In Python 2, use urllib2 which comes with the standard library.

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()

This is the most basic way to use the library, minus any error handling. You can also do more complex stuff such as changing headers. The documentation can be found here.

added 26 characters in body
Source Link
Corey
  • 14.3k
  • 7
  • 38
  • 35
Loading
added 290 characters in body
Source Link
Corey
  • 14.3k
  • 7
  • 38
  • 35
Loading
Source Link
Corey
  • 14.3k
  • 7
  • 38
  • 35
Loading