我试图让applescript点击(链接),我已经发布了下面的代码,我尝试了很多方法,但我无法让它工作。此外,链接是不同的每次,所以我不能只是复制链接到它。提前感谢!这也是所有的代码与它做(我认为)我想要它点击最后上传的日期:(链接)
<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&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到它;结果/目标将与点击相同。
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
编辑:在新的选项卡中打开url(如果在选项卡中打开链接在首选项中设置为自动),您可以将set URL of it to
更改为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