How do I extract the contents of a specified text field within a webpage using applescript?
Although the page you supplied is returning an image of the answers which means you cannot return text from it.

The source of the page holds the answer in text form in a javascript function.

This applescript is using one of my old methods to get the text between pattens.

I would probably now do this using ApplescriptOBJC but thought it better to keep it in Applescript with a dash of shell. As it may be more understandable.

tell application "Safari" to set theString to (source of document 1)

(* Strip the text and only return the last line*)
set input to do shell script "echo " &amp; (quoted form of theString) &amp; "|sed -n \"/stringified/,/mInput/p\" | sed '$!N;$!D'"



global answer

set offSet1 to "\"stringified\": \""
set offSet2 to "\",\"mInput\""


my strip(offSet1, offSet2, input)

return answer
on strip(offSet1, offSet2, thedata)
    (* Use the offsets of the pattens to match the text # thru # *)
    set textNumber1 to (offset of offSet1 in thedata)
    set theData1 to text -1 thru (textNumber1 + (count of offSet1)) of thedata
    set textNumber2 to (offset of offSet2 in theData1)
    set textString2 to text from word 1 to (textNumber2 - 1) of theData1
    set thedata to theData1
    set answer to textString2
end strip




Update. 

The OP has pointed out that there is an option to have a popup show the answer in plain text.

This is not obvious to anyone who is not familiar with the site. The popup does not exist in the page source until you click this option, which is the reason I could not find the classes the OP was referring to in the page source.



The first script above does not need you to click any option or get the popup.

But if for some reason you do then you can use this script which will require you to have the popup on display first.:

tell application "Safari"
    set input to do JavaScript "theclass = document.getElementsByClassName('popup ui-draggable')[0]; theclass.getElementsByTagName('PRE')[0].innerHTML;" in document 1
end tell