Applescript 使用谷歌浏览器提取文本 [英] Applescript use google chrome to extract text

查看:90
本文介绍了Applescript 使用谷歌浏览器提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 safari 的页面中提取文本,一切正常,但是我无法将此脚本调整为 Google Chrome

I'm extracting text from a page on safari, everything work fine, However I can't adapt this script to 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 代码

Here is the Chrome code

 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

出现错误预期的行尾但找到标识符."

have error "Expected end of line but found identifier."

推荐答案

Google Chrome"的命令和语法不一样.

The command and the syntax for "Google Chrome" is not the same.

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

You must use the execute javascript command instead of do javascript.

并且您必须从窗口中指定一个选项卡,而不是在文档 1 中的 .

And you must specify a tab from a window instead of 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

这篇关于Applescript 使用谷歌浏览器提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆