使用 Applescript/JavaScript 单击网页上的按钮 [英] Click Button on Webpage with Applescript/JavaScript
问题描述
我发现了其他几个类似的问题,但没有一个能解决我需要解决的确切问题.我试图模拟鼠标点击,以获得滚动的整个结果(例如,从这个网站:http://www.deadseascrolls.org.il/explore-the-archive/manuscript/4Q266-1) 可见.我特别想单击"显示图像底部中心的加载更多结果"项(但我认为这变得更加困难,因为站点的源编码).我想单击它直到显示所有结果.我写了以下 Applescript:
I have found several other similar questions, but none of them solve the precise problem I need to solve. I am attempting to simulate a mouse click, to get the entire results of a scroll (e.g., from this site: http://www.deadseascrolls.org.il/explore-the-archive/manuscript/4Q266-1) visible. I specifically want to "click" on the "Load More Results" item at the bottom centre of displayed images (but I think this made more difficult because of the source encoding at the site). I would like to click it until all results are displayed. I have written the following 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
end iaaScroll
但是,我无法成功地让 JavaScript 加载页面上的所有结果.我将如何成功地做到这一点?我不懂 JavaScript,非常感谢您的帮助.
I cannot, however, successfully get the JavaScript to load all the results on the page. How would I successfully do this? I do not know JavaScript, so your help is much appreciated.
推荐答案
此脚本将启动该网站并单击加载更多结果"一次..
This script will launch that website and click "load more results" one time..
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
打开该网页后..此脚本本身将单击加载更多结果"一次..每次运行该脚本时
Once that webpage is open..This script by itself will click "load more results" once.. Each time you run the script
tell application "Safari"
activate
do JavaScript "document.getElementById('loadmore').click();" in document 1
end tell
或者..因为你所谈论的那个特定页面最终加载了 416 张图片..我在脚本中添加了一个重复语句,它最终会加载该网站并显示所有图片..你可能需要调整延迟值但正如他们现在设置的那样,脚本在我的机器上完美运行
Or.. Since that specific page you are talking about ultimately loads 416 images.. I added a repeat statement in the script which will ultimately load that website with all of the images displayed.. You may need to tweak the delay values but as they are set now, the script runs perfectly on my machine
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
这篇关于使用 Applescript/JavaScript 单击网页上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!