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

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

问题描述

我从Safari浏览器页面提取文本,一切都做工精细,
不过,我可以在此脚本无法适应谷歌浏览器

I'm extracting text from a page on safari, everything work fine, However I can't adapt this script to Google Chrome

下面是Safari浏览器code

Here is the Safari code

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 code

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."

推荐答案

该命令的语法谷歌浏览器是不一样的。

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

您必须使用执行JavaScript的命令代替做的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天全站免登陆