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://www.cmegroup.com/cmews/mvc/productslate/v1/list/500/1?" 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
Post a Comment