单击带有Applescript / JavaScript的网页上的按钮

时间:2016-10-27 20:14:38

标签: javascript applescript

我找到了其他几个类似的问题,但没有一个能解决我需要解决的确切问题。我正在尝试模拟鼠标单击,以获得滚动的整个结果(例如,从此网站:http://www.deadseascrolls.org.il/explore-the-archive/manuscript/4Q266-1)可见。我特别希望"点击"在"加载更多结果"在显示图像的底部中心的项目(但我认为这更加困难,因为在网站上的源编码)。我想点击它直到显示所有结果。我写了以下Applescript:

on iaaScroll(myScroll)
tell application "Safari"
    activate
    open location "http://www.deadseascrolls.org.il/explore-the-archive/manuscript/" & myScroll & "-1" as string
    delay 2.0
    do JavaScript "var myDIV = document.getElementById('loadmore').getElementsByTagName('span')[0];  myDIV.dispatchEvent(new MouseEvent('mousedown')); myDIV.dispatchEvent(new MouseEvent('mouseup'));" in document 1
end tell

结束iaaScroll

但是,我无法成功地让JavaScript在页面上加载所有结果。我怎么成功做到这一点?我不懂JavaScript,所以非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

此脚本将启动该网站并单击“加载更多结果”一次..

tell application "Safari"
    activate
    set URL of document 1 to "http://www.deadseascrolls.org.il/explore-the-archive/manuscript/4Q266-1"
    delay 3
    do JavaScript "document.getElementById('loadmore').click();" in document 1
end tell

该网页打开后。此脚本本身会点击“加载更多结果”一次..每次运行脚本

tell application "Safari"
    activate
    do JavaScript "document.getElementById('loadmore').click();" in document 1
end tell

或..因为你所谈论的那个特定页面最终会加载416个图像..我在脚本中添加了一个重复声明,最终会加载该网站显示所有图像..您可能需要调整延迟值但是现在它们已经设置好了,脚本在我的机器上完美运行

tell application "Safari"
    activate
    set URL of document 1 to "http://www.deadseascrolls.org.il/explore-the-archive/manuscript/4Q266-1"
    delay 4 -- you may need to adjust your delay time to account for your    browser speed
    repeat 34 times -- adjust this number if there are more than 416 results
        do JavaScript "document.getElementById('loadmore').click();" in document 1
        delay 0.55 -- you may need to adjust your delay time to account for your browser speed
    end repeat
end tell