繁体   English   中英

使用Applescript / JavaScript在网页上单击按钮

[英]Click Button on Webpage with Applescript/JavaScript

我发现了其他几个类似的问题,但是没有一个可以解决我需要解决的精确问题。 我试图模拟鼠标单击,以显示滚动的整个结果(例如,从此站点: 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,因此非常感谢您的帮助。

该脚本将启动该网站,然后单击“加载更多结果”。

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张图像。.我在脚本中添加了一条repeat语句,该语句最终将使该网站加载所有显示的图像..您可能需要调整延迟值,但因为它们现在设置好了,脚本可以在我的机器上完美运行

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM