jerbear jerbear - 1 month ago 8
HTML Question

Fetch HTML From URL in Python

I am trying to read the

HTML
contents of a
URL
with
Python
. To fetch the
HTML
contents of a
URL
, would I use the module
wget
,
urllib
or a different module entirely?

After Answers:
I will use the
urllib
module since that comes with the default Python 2.7 build, and I can't download external modules from this computer.

List of Modules That Fetch URL Contents:

Wget
Beautiful Soup
Urllib
Requests

Answer

Here is a sample to get you started with requests:

import requests

resp = requests.get('http://httpbin.org/get')
if resp.ok:
    print (resp.text)
else:
    print ("Boo! {}".format(resp.status_code))
    print (resp.text)
Comments