urllib2 Error 403: Forbidden

zachary

I have posted to this site and received really helpful guidance, i return with another question.

Where have i gone wrong here, I was prettty sure this is what is required to access information from various sites. In this case, the CME Group.

   import urllib2

url = "http://www.cmegroup.com/trading/energy/natural-gas/natural-gas.html"
request= urllib2.Request(url)
handle = urllib2.urlopen(request)
content = handle.read()
splitted_page = content.split("<span class=\"cmeSubHeading\">", 1);
splitted_page = splitted_page[1].split("</span>", 1)
print splitted_page[0]

Error reads,

HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden

Thank you greatly in advance.

Cake

Actually the problem is that they block everyone who doesn't have a user-agent

import urllib2

request = urllib2.Request("http://www.cmegroup.com/trading/energy/natural-gas/natural-gas.html", None, {'User-Agent': 'Mozilla/5.0'})
content = urllib2.urlopen(request).read()
splitted_page = content.split("<span class=\"cmeSubHeading\">", 1);
splitted_page = splitted_page[1].split("</span>", 1)
print splitted_page[0]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related