如何使用 Javascript 通过 Applescript 抓取 HTML 片段 [英] How to grab HTML snippet via Applescript with Javascript

查看:32
本文介绍了如何使用 Javascript 通过 Applescript 抓取 HTML 片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的详细情况.

我想出了如何登录网站,而不是使用 javascript,而是使用击键"、选项卡"和返回"来查找用户名和密码字段.我知道随着网站的变化这可能不可靠,但现在我只是想保持简单.

I have figured out how to login to a website, not using javascript, but using "keystrokes", "tabs" and "returns" to find the username and password fields. I know this can be unreliable as websites change but for now I am just trying to keep it simple.

在我登录某个网站(例如银行账户)后,我想获取账户余额并将其导入 Numbers.

After I log in to a site, like a bank account, I want to grab the account balance and import it to Numbers.

我已经想出了如何在 Numbers 中的特定单元格中插入预先确定的文本,并且可能可以将其扩展到对话框等,但这并不是我真正想要完成的.

I have figured out how to insert a predermined text into a specific cell in Numbers and probably could expand that to dialog boxes ect, but that is not what I am really trying to accomplish.

基本上我不知道我需要做什么才能在登录后从当前网站获取数据.做研究后我意识到这是与 javascript 相关的事情.

Basically I don't know what I need to do to grab the data from the current website after I have logged in. Doing research I realize it is something todo with javascript.

现在并将其应用于更大的计划,我只想知道如何定位我不必通过 Safari 登录 Safari 的网站的数据,并在 Applescript 编辑器的结果中显示数据.我想弄清楚如何使用该结果在另一个应用程序(ei Numbers)中显示它.然后我会将其应用到其他网站,因此我想确切地知道在哪里可以找到数据.

For now and to apply it to the bigger plan, I just want to know how to locate data of a website that I do not have to log into in Safari via javascript and display the data in the results of Applescript Editor. And I am trying to figure out how I could use that result to display it in another application (ei Numbers). I then would apply this to other sites, so I would like to know exactly where to look to find the data.

我认为股票网站是一个很好的例子,但我很难找到适合这个例子的网站.

I am thinking that stock websites would be a great example but I am having a tough time finding one that fits this example.

感谢您的帮助!

推荐答案

我只想知道如何定位我没有的网站的数据通过javascript登录Safari

I just want to know how to locate data of a website that I do not have to log into in Safari via javascript

这可以通过 JavaScript 轻松完成:使用它您可以通过 class, 名称, id,遍历它们向上inwards 并获取它们的属性,例如 texthtml 内容.请告诉我们您尝试了哪些方法以及您遇到了哪些错误:没有人可以为您学习 JavaScript.

This can be easely done with JavaScript: with it you may get dom element(s) by class, name, id, traverse them upwards or inwards and get their properties like text and html content. Please tells us what have you tried and which error do you get: nobody can learn JavaScript for you.

并在 Applescript 编辑器的结果中显示数据.

and display the data in the results of Applescript Editor.

要将变量从 JavaScript 传递到 AppleScript,您只需在 js 代码中包含一个 return 语句.

All you have to do to pass a variable from JavaScript to AppleScript is to include a return statement in your js code.

property myVar : missing value
tell application "Safari"
    set myVar to do JavaScript "
var myVar = " & myVar & ";
myVar = myVar + 1;
return myVar;
" in document 1
end tell
display dialog myVar

do JavaScript 命令,特定于 Safari,将返回与它执行的脚本返回的相同的值.因此,您可以将网页中的任何值保存到您的苹果脚本中.

The do JavaScript command, which is specific to Safari, will return the same value returned by the script it executes. Hence, you may save any value from a webpage to your applescript.

这篇关于如何使用 Javascript 通过 Applescript 抓取 HTML 片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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