Applescript | Javascript - 使用Javascript点击链接? [英] Applescript | Javascript - Click on Link using Javascript?

查看:104
本文介绍了Applescript | Javascript - 使用Javascript点击链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想点击(链接)获取Applecript,我已经发布了下面的代码,我尝试了很多方法,但我无法让它工作。此外链接每次都不同,所以我不能将该链接复制到其中。提前致谢!这也是它的所有代码(我认为)我希望它点击上次上传的日期:(链接)

I am trying to get applescript to click on the (link), I have posted the code below, i have tried many ways but i am unable to get it work. Also the link is different every time so i cant just copy that link into it. Thanks in advanced! Also This is all the code to do with it (I think) i want it to click on the date of last upload: (Link)

<div class="span4 offset1">
                            <ul class="unstyled">
                                <li>Monthly Views: <strong class="pull-right"><a href="#" class="data-na" data-original-title="" title="">NA</a></strong></li>
                                <li>Daily New Views: <strong class="pull-right">18,830</strong></li>
                                <li>Daily New Subscribers: <strong class="pull-right">33</strong></li>
                                <li>Total Views: <strong class="pull-right">298,481</strong></li>
                                <li>Total Channel Views: <strong class="pull-right">3,467</strong></li>
                                <li>Total Subscribers: <strong class="pull-right">649</strong></li>
                                <li id="date-of-last-upload">Date of Last Upload: <a href="https://www.youtube.com/watch?v=YVrV-OmDJcw&amp;feature=youtube_gdata" target="_BLANK">(link)</a><strong class="pull-right">14-01-10 @ 08:18:36 pm</strong></li>
                                <li class="clearfix">Partner:
                                    <strong class="pull-right">
                                                                                                                                                                TheDeeman25+user                                                                                                                    </strong>
                                </li>
                            </ul>
                        </div>


推荐答案

我不确定这是不是你的答案正在寻找,但你可以通过获取 childNodes 来获得锚标记的href属性的值。 JavaScript返回的值是您最终要设置文档的URL。我没有使用点击,而是获得所需的位置,并将文档1的URL设置为它;结果/目标与点击相同。

I'm not sure if this is the answer you're looking for but you can get the value of the href attribute of the anchor tag by getting childNodes. The value returned by JavaScript is the URL you want to set your document eventually. Instead of using a click I get the desired location and set the URL of document 1 to it; the result/goal will be the same as a click.

tell application "Safari"
    tell document 1
        set URL of it to do JavaScript "document.getElementById('date-of-last-upload').childNodes[1].href"
    end tell
end tell

编辑:要在新标签中打开网址(如果标签中的打开链接在首选项中设置为自动),您可以更改将其设置为,将其设置为打开位置

to open the url in a new tab (if opening links in tab is set to automatic in preferences) you can change the set URL of it to into open location

tell application "Safari"
    tell document 1
        open location (do JavaScript "document.getElementById('date-of-last-upload').childNodes[1].href")
    end tell
end tell 

这篇关于Applescript | Javascript - 使用Javascript点击链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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