我在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
有错误"预期结束但找到了标识符。"
答案 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