JS写的自动登录、自动提交的代码
JS不仅可以在浏览器端受安全限制的执行,实现绚丽的网页特效,还可以在服务器端写ASP,实现比VBS功能更强大,更容易开发的WEB程序。但是,很多人不知道的是,JS还可以写应用程序,实现对本地计算机的控制,其中一个很常见的任务就是自动登录和自动注册。通常JS脚本适合与无人看守的自动化任务,但是结合InternetExplorer.Application我们就可以结合IE的可视化界面和本地JS应用程序强大功能了。
在浏览器里执行JS,通常会收到浏览器的安全限制,例如不能读取本地文件系统,读取数据库,不能跨域访问。桌面执行的JS却拥有和普通应用程序一样的权限。但是,JS程序更简单,更容易开发。下面就以自动提交表单为例。
01.//创建一个IE窗口 02.var ie = new ActiveXObject(“InternetExplorer.Application”); 03.//显示 04.ie.visible = true; 05. 06.//导向http://www.scriptlover.com/wish/input.asp 07.ie.navigate(“http://www.baidu.com/gaoji/advanced.html”); 08.//等待加载完毕 09.while(ie.busy){WScript.sleep(100);} 10. 11.//获得window和document和表单的引用 12.var document = ie.document; 13.var window = document.parentWindow; 14.var form = document.forms[0]; 15. 16.//接下来向表单填数据,这里的数据是硬编码到程序里,你完全可以用JS读取SQL SERVER、ACCESS甚至以数据库形式读取EXCEL文件的内容 17.//关于如何确定表单的域的名称,最好的方法是用FIREFOX的FIREBUG插件 18. 19.form.q1.value = “漂泊云间”; 20.//暂停,以便看到效果 21.WScript.sleep(1000); 22. 23.//rn是下拉列表,我们随机选取一个 24.form.rn.value = form.rn.options[Math.floor(Math.random() * form.rn.options.length)].value; 25.//暂停,以便看到效果 26.WScript.sleep(1000); 27. 28.//lm依然 29.form.lm.value = form.lm.options[Math.floor(Math.random() * form.lm.options.length)].value; 30.//暂停,以便看到效果 31.WScript.sleep(1000); 32. 33.//ct是单选框,随便选中一个 34.form.ct[Math.floor(Math.random() * form.ct.length)].checked = 1; 35.//暂停,以便看到效果 36.WScript.sleep(1000); 37. 38.//ft是下拉列表,我们随机选取一个 39.form.ft.value = form.ft.options[Math.floor(Math.random() * form.ft.options.length)].value; 40.//暂停,以便看到效果 41.WScript.sleep(1000); 42. 43.//q5依然 44.form.q5[Math.floor(Math.random() * form.q5.length)].checked = 1; 45.//暂停,以便看到效果 46.WScript.sleep(1000); 47. 48.//改成当前页提交 49.form.target = “_self”; 50.//暂停,以便看到效果 51.WScript.sleep(2000); 52. 53.//提交,有两种办法,form.submit和提交按钮的click方法 54.form.elements[1].click();下面是最后一步了,保存为JS文件例如1.js,然后执行。默认是用WScript.exe来执行。如果你更改了JS的文件关联,只好用命令行了。cd到1.js所在的目录,然后执行 wscript.exe 1.js
你就可以看到效果了。
好像有点看不懂!水品还有待提高!!
Good evening, I am beautiful young Kiev lady with magnetic eyes, soft silky skin and natural breast.. Independent Kiev. Young Kiev lady will be able to entertain you in her Kiev apartment in the center or visit you anywhere in Kiev. I belong to you.
Welcome back,we missed you. Take care,
Very heartwarming.
I love this humour…:)
The thought of going on really appeals to me.
I read your blog everyday.You are an inspiration in my life