jerbear
jerbear

Reputation: 41

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

Upvotes: 0

Views: 5164

Answers (1)

Robᵩ
Robᵩ

Reputation: 168596

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)

Upvotes: 5

Related Questions