本文主要讲解如何使用AppleScript+JavaScript脚本实现校园网自动认证。 实现自动打开浏览器,自动输入用户名密码和选择营业厅,完成登陆后自动关闭浏览器。 1.1前面这一部分是用AppleScript打开safari浏览器并转到校园网登陆页面。 1.2然后嵌入一段JavaScript代码(因为AppleScript无法实现抓取页面内容的操作),s.options[1].selected有两行是因为我们学校的校园网中国移动那个option是已经selected的,但是页面不显示,经过反复试验,可以先选择中国电信再选择中国移动。 在系统偏好设置->安全与隐私->辅助功能,要打开脚本编译器才能够顺利运行脚本。文章目录
一、介绍
二、实现过程
1.打开AppleScript 编辑器
2.代码
2.1登陆脚本
tell application "Safari" activate make new document with properties {URL:"https://10.3.130.12"}--打开校园网 delay 1 -- 暂停 1 秒 tell document 1 do JavaScript " document.getElementById('username').value=188xxxxxxxx;--学号 var s = document.getElementById('domain'); s.options[1].selected = true;//刷新页面 s.options[2].selected = true; document.getElementById('password').value=xxxxxx;--密码 document.getElementById('login').click(); " end tell delay 1 close document 1 end tell say "Wi-Fi连接成功"
2.2退出脚本
tell application "Safari" activate make new document with properties {URL:"https://10.3.130.12"} delay 0.5 -- 暂停 0.5 秒 tell document 1 do JavaScript "document.getElementById('logout').click();" end tell delay 0.5 close document 1 end tell
3.结果
三、代码讲解和常见问题
1.代码讲解
tell application "Safari" activate make new document with properties {URL:"https://10.3.130.12"}--打开校园网 delay 1 -- 暂停 1 秒 tell document 1
do JavaScript " document.getElementById('username').value=188xxxxxxxx;--学号 var s = document.getElementById('domain'); s.options[1].selected = true;//刷新页面 s.options[2].selected = true; document.getElementById('password').value=xxxxxx;--密码 document.getElementById('login').click(); "
1.3执行完毕之后关闭当前页面。 delay 1 close document 1
2.常见问题
2.1安全与隐私
2.2Safari开发选项设置
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算