我正在尝试使用AppleScript从一个网站上获取一些信息,我总是得到“期望的行尾等,但找到标识符”。突出显示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我也尝试过,但失败了
tell application "Google Chrome"
activate
set theScript to "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;"
do JavaScript theScript in current tab of first window
end tell谢谢你的帮助!
发布于 2016-07-16 11:57:46
我的整个代码(非常简短)现在如下所示。我无法获得代码来发布它从javascript中获得的信息到列b中。你会怎么做来解决这个问题呢?再次感谢您。
将i设置为1
重复725次
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)
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
发布于 2016-07-15 15:11:44
看一下脚本字典的内部。没有为Google Chrome定义do javascript-handler。相反,您将找到execute:
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如果在这一端调用这个处理程序
getInputByClass("current-site-link site-link js-gps-track", 0)你应该得到
<div class=\"site-icon favicon favicon-stackoverflow\" title=\"Stack Overflow\"></div>
Stack Overflow结果。
祝你玩得开心,迈克尔/汉堡
https://stackoverflow.com/questions/38384322
复制相似问题