Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: urlread2 get with headers
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 2
Registered: 1/18/12
urlread2 get with headers
Posted: Aug 19, 2014 8:15 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I'm trying to download some stats from a footy website, it requires me to connect to it to get the token then to use the token when requesting the data. I have it working in python but I'm trying to get it working in Matlab using urlread2 (http://www.mathworks.com/matlabcentral/fileexchange/35693-urlread2)
I'm also using jason lab to parse the json data when it returns

Yet im having some problems.

Getting the token works fine

addpath('C:\Users\Paul\Desktop\AFL Scraping\Matlab\jsonlab');
base_url = 'http://www.afl.com.au/api/cfs/afl/'
token_url = [base_url 'WMCTok']
player_url = [base_url 'statsCentre/teams']
str = urlread(token_url,'post',{'0','0'})
token = json2data.token

But the next step I can't figure out.
The curel request from the site is
curl "http://www.afl.com.au/api/cfs/afl/statsCentre/teams?competitionId=CD_S2014014&roundId=CD_R201401401"

and the token header is {'X-media-mis-token': token}

The python code that works in case anyone is interested is
import requests
import json
import csv
base_url = 'http://www.afl.com.au/api/cfs/afl/'
token_url = base_url + 'WMCTok'
player_url = base_url + 'statsCentre/teams'
session = requests.Session() # session makes it simple to use the token across the requests
token = session.post(token_url).json()['token'] # get the token
session.headers.update({'X-media-mis-token': token}) # set the token
data = session.get(player_url + '?competitionId=CD_S2014014&roundId=CD_R201401401')
def printPretty(data):
print(json.dumps(data, sort_keys=True, indent=2, separators=(',', ': ')))


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2015. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.