AppleScript的点击搜索结果/其他网页按钮和链接? [英] Applescript to click on search results/other web page buttons and links?

查看:511
本文介绍了AppleScript的点击搜索结果/其他网页按钮和链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何使用AppleScript的点击在谷歌搜索网页链接。我可以通过名称或数字或任何识别他们?

How would I use Applescript to click on a web link in a google search. Can I identify them by name or number or anything?

推荐答案

Safari浏览器:

Safari:

tell application "Safari"
    open location "http://google.com/search?q=example"
    do JavaScript "window.addEventListener('load', function() {
      document.querySelectorAll('.r a')[0].click()
    })" in document 1
end tell

浏览器:

tell application "Google Chrome"
    open location "http://google.com/search?q=example"
    tell active tab of window 1
        execute javascript "window.addEventListener('load', function() {
          document.querySelectorAll('.r a')[0].click()
        })"
    end tell
end tell

编辑:尝试这样的事情按标题匹配YouTube的结果是:

try something like this to match a YouTube result by title:

document.querySelector('.yt-uix-tile-link').click()

编辑2:修改的window.onload =函数(){} window.addEventListener('负荷',函数(){})

这篇关于AppleScript的点击搜索结果/其他网页按钮和链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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