Delphi,461字节,553字节
现在也可以处理多个页面!
打高尔夫球:
uses IdHTTP,RegularExpressions;var T,S,O:String;K,V,C:Int32;begin repeat Inc(C);Str(C,S);S:=TIdHTTP.Create.Get('http://codegolf.stackexchange.com/questions/34705/output-the-answer-above-yours?page='+S);T:=T+S;until Pos('<span class="page-numbers next',S)=0;O:='Top!';for T in TRegEx.Split(T,'<a name="') do begin S:=T;Val(Copy(S,1,Pos('"',S)-1),K,C);if C=1then Continue;Delete(S,1,Pos('post ">',S)+6);Val(Copy(S,1,Pos('<',S)-1),V,C);C:=Pos('<code>',S);if(C=0)or(V<0)then Continue;if K=34844then Break;O:=Copy(S,C+6,Pos('</code>',S)-C-6);end;Write(O)end.
(略)未打高尔夫球:
uses
IdHTTP,RegularExpressions;
var
T,S,O:String;
K,V,C:Int32;
begin
// download all pages in thread and concat them
repeat
Inc(C);
Str(C,S);
S:=TIdHTTP.Create.Get('http://codegolf.stackexchange.com/questions/34705/output-the-answer-above-yours?page='+S);
T:=T+S;
until Pos('<span class="page-numbers next',S)=0;
O:='Top!'; // initialize code string to 'Top!'
for T in TRegEx.Split(T,'<a name="') do begin
S:=T;
Val(Copy(S,1,Pos('"',S)-1),K,C); // try to extract user id
if C=1then Continue; // if failed, continue loop
Delete(S,1,Pos('post ">',S)+6); // prepare S for next parse
Val(Copy(S,1,Pos('<',S)-1),V,C); // try to extract vote count
C:=Pos('<code>',S); // check if <code> tag exists
if(C=0)or(V<0)then Continue; // make sure vote count is positive and <code> tag exists
if K=34844then Break; // if its our answer, break the loop
O:=Copy(S,C+6,Pos('</code>',S)-C-6); // get string in <code> tag
end;
Write(O); // write <code> string
end.
如何运行:
app.exe > output.txt