url - Python access server urlopen() -


i wanted access data stored in site using following code:

import urllib import re import json  htmltext = urllib.urlopen("http://www.cmegroup.com/cmews/mvc/productslate/v1/list/500/1?sortfield=oi&sortasc=false&venues=3&page=1&cleared=1&group=1&r=esxqs2si").read()  print htmltext  #data = json.load(htmltext) 

i response:

you don't have permission access "http&#58;&#47;&#47;www&#46;cmegroup&#46;com&#47;cmews&#47;mvc&#47;productslate&#47;v1&#47;list&#47;500&#47;1&#63;" on server.<p> 

is there way access information, or there way extract info provided link?

as link accessible browser, looks server not allow plain html requests (without user-agent header). can mimic such request using urllib2

import urllib2  url = "http://www.cmegroup.com/cmews/mvc/productslate/v1/list/500/1?sortfield=oi&sortasc=false&venues=3&page=1&cleared=1&group=1&r=esxqs2si" user_agent = 'mozilla/4.0 (compatible; msie 5.5; windows nt)' headers = { 'user-agent' : user_agent }  req = urllib2.request(url, headers=headers)  response = urllib2.urlopen(req)  your_json = response.read() response.close() 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -