2

I am trying to use urlread to grab the contents of a password protected website. When I'm logged in, the url is http://media.nba.com/Stats/OfficialBoxScores.aspx, and when logged out, the url is http://media.nba.com/Stats/Login.aspx?ReturnUrl=%2fStats%2fOfficialBoxScores.aspx. I've tried

urlread('http://media.nba.com/Stats/OfficialBoxScores.aspx','Username','username','Password','password');

with my login credentials but it only gives me the contents of the url before logging in. I see that this question has been asked before, but I couldn't find a solution for my situation. Is there a way to use urlread to get past the password protection wall?

Any help would be greatly appreciated!

dwm8
  • 309
  • 3
  • 16
  • Imitate POST request, submitting the data from the form with username and password, get response with cookies, use those cookies with every further request. But this is not what Matlab was created for. Why not to use something external, like `wget`, for example? – Cheery Oct 13 '14 at 22:31
  • Basically I'm trying to integrate this code into an existing MATLAB script. I'm very much so a MATLAB novice and have even less experience with pulling data from the web. Could the `wget` method be integrated into MATLAB code using the `system` function or in some other way? – dwm8 Oct 13 '14 at 22:42
  • It is not a method - external console program. The main problem here is to keep and use cookies with every request - they might have session ID which identifies you as logged in user. – Cheery Oct 13 '14 at 23:03

2 Answers2

0

You need to specify the method (use 'post'), and the parameters need to be a cell array of name/value pairs.

Does this work :

urlread('http://media.nba.com/Stats OfficialBoxScores.aspx','post',{'Username','username';'Password','password'} );
Hoki
  • 11,637
  • 1
  • 24
  • 43
0
%Allows you to access url that requires username and password

url_login = 'https://www.your-website-loginpage'
url_data = 'https://www.your-website-data-url'
[stat,h] = web(url_login) %Enter username and password in the popup
setCurrentLocation(h, url_data)
pageText = h.getHtmlText()
beaker
  • 16,331
  • 3
  • 32
  • 49
Blake
  • 1