首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自getInfoByClass的简单错误?

来自getInfoByClass的简单错误?
EN

Stack Overflow用户
提问于 2016-07-15 05:10:46
回答 2查看 47关注 0票数 0

我正在尝试使用AppleScript从一个网站上获取一些信息,我总是得到“期望的行尾等,但找到标识符”。突出显示JavaScript的错误

以下是错误代码的部分

代码语言:javascript
复制
to getInputByClass(theClass, num)

    tell application "Google Chrome" 

        set input to do JavaScript "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" in document 1 

    end tell

    return input

end getInputByClass

我也尝试过,但失败了

代码语言:javascript
复制
tell application "Google Chrome"
    activate
    set theScript to "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;"
    do JavaScript theScript in current tab of first window
end tell

谢谢你的帮助!

EN

回答 2

Stack Overflow用户

发布于 2016-07-16 11:57:46

我的整个代码(非常简短)现在如下所示。我无法获得代码来发布它从javascript中获得的信息到列b中。你会怎么做来解决这个问题呢?再次感谢您。

将i设置为1

重复725次

代码语言:javascript
复制
activate application "Microsoft Excel"

tell application "Microsoft Excel"
    select cell ("a" & (i as string))
end tell

tell application "System Events"
    keystroke "c" using command down
    delay 1
end tell

activate application "Google Chrome"

tell application "System Events"
    keystroke "t" using command down
    delay 1
    keystroke "https://bookscouter.com/prices.php?isbn="
    keystroke "v" using command down
    keystroke "&searchbutton=Sell"
    delay 1
    keystroke return
    delay 10
end tell

set theText to getInputByClass("book-prices", 0)
tell application "Microsoft Excel"
    set value of cell ("b" & (i as string)) to theText
end tell

set i to i + 1

tell application "System Events"
    keystroke "w" using command down
end tell

结束重复

到getInputByClass(theClass,num)

代码语言:javascript
复制
tell application "Google Chrome"
    tell active tab of window 1
        set input to execute javascript "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;"
    end tell
end tell

return input

结束getInputByClass

票数 1
EN

Stack Overflow用户

发布于 2016-07-15 15:11:44

看一下脚本字典的内部。没有为Google Chrome定义do javascript-handler。相反,您将找到execute

代码语言:javascript
复制
to getInputByClass(theClass, num)

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

    return input

end getInputByClass

如果在这一端调用这个处理程序

代码语言:javascript
复制
getInputByClass("current-site-link site-link js-gps-track", 0)

你应该得到

代码语言:javascript
复制
<div class=\"site-icon favicon favicon-stackoverflow\" title=\"Stack Overflow\"></div>
            Stack Overflow

结果。

祝你玩得开心,迈克尔/汉堡

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38384322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档