MATLAB: How to make a list of user’s reputation ? :)

MATLABmatlab answersmeta

Well, how did you do it?

Best Answer

S = urlread('http://www.mathworks.com/matlabcentral/answers/contributors/2710900'); % 2710900 is your user number.
I = findstr(S,'<div class="value">');
regexp(S(I+19:I+22),'\d+','match')
For the name:
I = findstr(S,'<h1 class="fn">');
regexp(S(I:I+40),'(?<=\">)\w+','match')
So you need to get the user numbers and loop through. The only issue is the user numbers don't appear to be consecutive. This would mean try catch on numbers 1 through ??.
EDIT
I used this code, letting it run for about 8 minutes and got only 3 users,
JoshIsCool - number 1, Patrick - number 2, Rhonda - number 385
all have reputation 0. The code was on number 589 when I ctrl+c it. So this method would be an overnight run the first night. Then using the stored numbers would make it easier!
cnt = 1;
for ii = 1:3000000
try
S = urlread(['http://www.mathworks.com/matlabcentral/answers',...
'/contributors/',sprintf('%i',ii)]);
catch
continue
end
I = findstr(S,'<h1 class="fn">');
N = regexp(S(I:I+40),'(?<=\">)\w+','match') % dump to command...
if ~isempty(N)
NM{cnt} = N; % Growing is nothing compared to urlread!
I = findstr(S,'<div class="value">');
R = regexp(S(I+19:I+22),'\d+','match');
N{cnt} = ii; % For making this easier next time!
REP{cnt} = R;
cnt = cnt + 1;
end
end
EDIT2
O.k., so here is what I ended up doing. I went to google and did this search:
"inurl:matlabcentral answers contributors" site:mathworks.com
with 100 results per page, there were only four pages. So I then saved them to disk. From there I ran the below code:
Uold = 'gggggg';
cnt = 1;
for ii = 1:4
% This is the saved file.
s = urlread(['file:///', 'C:\Users\matt fig\Documents\search',sprintf('%i',ii),'.htm']);
% Read the links to the pages.
I = findstr(s,'www.mathworks.com/matlabcentral/answers/contributors/');
for jj = 1:length(I)
% Find the specific jjth page.
U = regexp(s(I(jj):I(jj)+90),'www.+?(?=["|+])','match');
if strcmp(U,Uold)
continue
end
s2 = urlread(['http://',U{1}]);
I2 = findstr(s2,'<h1 class="fn">'); % Looking for the name.
N = regexp(s2(I2:I2+40),'(?<=\">)\w+\s*\w*','match'); % The name
if ~isempty(N)
disp(N) % Display name.
NM{cnt} = N{1}; % Store the name
I2 = findstr(s2,'<div class="value">'); % looking for reput.
R = regexp(s2(I2+19:I2+22),'\d+','match');
REP{cnt} = R{1}; % Store the reputation
cnt = cnt + 1;
end
Uold = U;
end
end
[NM,JJ] = unique(NM);
REP = REP(JJ);
REP = cellfun(@str2double,REP);
[REP,G] = sort(REP,'descend');
NM = NM(G);
fid = fopen('answersnames.txt','w+');
for ii = 1:length(NM)
fprintf(fid,'%s %i\n',NM{ii},REP(ii));
end
fclose(fid)
This printed all to a nice text file in about 5 minutes. Now if anyone knows how to manipulate google programatically, this would work on autopilot.