使用Applescript/JavaScript在网页上单击按钮 [英] Click Button on Webpage with Applescript/JavaScript
问题描述
我发现了其他几个类似的问题,但是没有一个能够解决我需要解决的精确问题.我正在尝试模拟鼠标单击,以获取滚动的整个结果(例如,从此站点:
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张图像..我在脚本中添加了一条repeat语句,该语句最终将使该网站加载所有显示的图像..您可能需要调整延迟值但是现在设置好了,脚本可以在我的机器上完美运行
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屋!