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

查看:29
本文介绍了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:

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=function(){} 更改为 window.addEventListener('load',function(){}).

Edit 2: changed window.onload=function(){} to window.addEventListener('load',function(){}).

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

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