ฉันจะใช้ Applescript และ Safari เพื่อแยกคำตอบจากไซต์นี้ได้อย่างไร: http://www.wolframalpha.com/input/?i=whats+the+meaning+to+life%3F
ฉันพยายามแยกคำตอบเป็นข้อความธรรมดาที่คัดลอกได้ นั่นคือ, .txt
รูป
ฉันได้รับข้อผิดพลาดนี้:
"Can’t make text items 2 thru -1 of "missing value" into type text.
เมื่อใช้งานสคริปต์ต่อไปนี้:
to getInputByClass(theClass, num)
tell application "Safari"
set input to do JavaScript "
document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" in document 1
end tell
return input
end getInputByClass
to extractText(searchText, startText2, endText)
set tid to AppleScript's text item delimiters
set startText1 to "x"
set searchText to ("x" & searchText)
set AppleScript's text item delimiters to startText1
set endItems to text item -1 of searchText
set AppleScript's text item delimiters to endText
set beginningToEnd to text item 1 of endItems
set AppleScript's text item delimiters to startText2
set finalText to (text items 2 thru -1 of beginningToEnd) as text
set AppleScript's text item delimiters to tid
return finalText
end extractText
getInputByClass("popup ui-draggable", 0)
set theText to getInputByClass("r", 0)
set theResult to extractText(theText, "<pre>", "</pre>")
Code-level programming questions (cocoa, LLVM, etc…) **are off-topic here**. We do encourage AppleScript, Automator, and UNIX shell scripting questions as well as how to use tools like Xcode for non-language specific tasks.
"