Applescript使用谷歌浏览器提取文本

时间:2016-05-18 12:29:52

标签: google-chrome applescript extract

我在Safari上从一个页面中提取文本,一切正常, 但是,我无法将此脚本改编为Google Chrome

这是Safari代码

to getInputByClass2(theClass, num) 
    tell application "Safari" 
        set input to do JavaScript "
document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" in document 1 
    end tell
    return input 
end getInputByClass2

以下是Chrome代码

 to getInputByClass2(theClass, num) 
    tell application "Google Chrome" 
        set input to do JavaScript "
document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" in document 1 
    end tell
    return input 
end getInputByClass2

有错误"预期结束但找到了标识符。"

1 个答案:

答案 0 :(得分:1)

Google Chrome ”的命令和语法不一样。

您必须使用execute javascript命令而不是do javascript

您必须从窗口而不是in document 1指定标签。

tell application "Google Chrome"
    tell active tab of window 1 to set input to execute javascript "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;"
end tell
相关问题