Javascript Windows机器上网站的自动登录脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6248679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automatic login script for a website on windows machine?
提问by munish
I saw some guy had a file (I guess a batch file). On clicking of the batch file he was able to log in to multiple sites. (Perhaps it was done using VB.)
我看到有人有一个文件(我猜是一个批处理文件)。单击批处理文件后,他就可以登录到多个站点。(也许它是使用 VB 完成的。)
I looked for such a script on Google but didn't find anything useful.
我在谷歌上寻找这样的脚本,但没有找到任何有用的东西。
I know a bit of C++ and UNIX (also some HTML and JavaScript). I don't know if it can be done on a windows machine using these languages, but even if it could be done I think it would be difficult compared to VB or C## or some other high level languages.
我知道一点 C++ 和 UNIX(还有一些 HTML 和 JavaScript)。我不知道是否可以在使用这些语言的 windows 机器上完成,但即使可以完成,我认为与 VB 或 C## 或其他一些高级语言相比,这将很难。
I learned how to open multiple sites using basic windows batch commands enclosed in a batch file like:
我学会了如何使用包含在批处理文件中的基本 Windows 批处理命令打开多个站点,例如:
start http://www.gmail.com
start http://stackoverflow.com
But still I can't figure out how actually clicking on the batch file would help me to log in to the sites without even typing the username and password.
但我仍然无法弄清楚单击批处理文件实际上如何帮助我登录网站,甚至无需输入用户名和密码。
Do I need to start learning Visual Basic, .NET, or windows batch programming to do this?
我是否需要开始学习 Visual Basic、.NET 或 Windows 批处理编程才能执行此操作?
One more thing: can I also use it to log in to remote desktops?
还有一件事:我也可以用它登录远程桌面吗?
回答by mkilmanas
From the term "automatic login" I suppose security (password protection) is not of key importance here.
从术语“自动登录”来看,我认为安全性(密码保护)在这里并不重要。
The guidelines for solution could be to use a JavaScript bookmark (idea borrowed form a nice game published on M&M's DK site).
解决方案的指导方针可能是使用 JavaScript 书签(从M&M 的 DK 站点上发布的一个不错的游戏借来的想法)。
The idea is to create a javascript file and store it locally. It should do the login data entering depending on current site address. Just an example using jQuery:
这个想法是创建一个javascript文件并将其存储在本地。它应该根据当前站点地址进行登录数据输入。只是一个使用 jQuery 的例子:
// dont forget to include jQuery code
// preferably with .noConflict() in order not to break the site scripts
if (window.location.indexOf("mail.google.com") > -1) {
// Lets login to Gmail
jQuery("#Email").val("[email protected]");
jQuery("#Passwd").val("superSecretPassowrd");
jQuery("#gaia_loginform").submit();
}
Now save this as say login.js
现在将其另存为 login.js
Then create a bookmark (in any browser) with this (as an) url:
然后使用这个(作为)url 创建一个书签(在任何浏览器中):
javascript:document.write("<script type='text/javascript' src='file:///path/to/login.js'></script>");
Now when you go to Gmail and click this bookmark you will get automatically logged in by your script.
现在,当您转到 Gmail 并单击此书签时,您的脚本将自动登录。
Multiply the code blocks in your script, to add more sites in the similar manner. You could even combine it with window.open(...)
functionality to open more sites, but that may get the script inclusion more complicated.
将脚本中的代码块相乘,以类似的方式添加更多站点。您甚至可以将它与window.open(...)
功能结合起来打开更多站点,但这可能会使脚本包含更加复杂。
Note: This only illustrates an idea and needs lots of further work, it's not a complete solution.
注意:这只是一个想法,需要大量的进一步工作,它不是一个完整的解决方案。
回答by qwerty jones
The code below does just that. The below is a working example to log into a game. I made a similar file to log in into Yahoo and a kurzweilai.net forum.
下面的代码就是这样做的。以下是登录游戏的工作示例。我制作了一个类似的文件来登录雅虎和 kurzweilai.net 论坛。
Just copy the login form from any webpage's source code. Add value= "your user name" and value = "your password". Normally the -input-elements in the source code do not have the value attribute, and sometime, you will see something like that: value=""
只需从任何网页的源代码中复制登录表单即可。添加值=“您的用户名”和值=“您的密码”。通常源代码中的-input-元素没有 value 属性,有时,您会看到类似这样的内容: value=""
Save the file as a html on a local machine double click it, or make a bat/cmd file to launch and close them as required.
在本地机器上将文件另存为 html,双击它,或者制作一个 bat/cmd 文件以根据需要启动和关闭它们。
<!doctype html>
<!-- saved from url=(0014)about:internet -->
<html>
<title>Ikariam Autologin</title>
</head>
<body>
<form id="loginForm" name="loginForm" method="post" action="http://s666.en.ikariam.com/index.php?action=loginAvatar&function=login">
<select name="uni_url" id="logServer" class="validate[required]">
<option class="" value="s666.en.ikariam.com" fbUrl="" cookieName="" >
Test_en
</option>
</select>
<input id="loginName" name="name" type="text" value="PlayersName" class="" />
<input id="loginPassword" name="password" type="password" value="examplepassword" class="" />
<input type="hidden" id="loginKid" name="kid" value=""/>
</form>
<script>document.loginForm.submit();</script>
</body></html>
Note that -script- is just -script-. I found there is no need to specify that is is JavaScript. It works anyway. I also found out that a bare-bones version that contains just two input filds: userName and password also work. But I left a hidded input field etc. just in case. Yahoo mail has a lot of hidden fields. Some are to do with password encryption, and it counts login attempts.
请注意,-script- 只是-script-。我发现不需要指定是 JavaScript。无论如何它都有效。我还发现只包含两个输入字段的准系统版本:用户名和密码也可以使用。但是为了以防万一,我留下了一个隐藏的输入字段等。雅虎邮箱有很多隐藏字段。有些与密码加密有关,它会计算登录尝试次数。
Security warnings and other staff, like Mark of the Web to make it work smoothly in IE are explained here:
安全警告和其他人员,如 Web 标记,使其在 IE 中顺利运行,解释如下:
回答by Mark Lakata
I used @qwertyjones's answer to automate logging into Oracle Agile with a public password.
我使用@qwertyjones 的回答使用公共密码自动登录到 Oracle Agile。
I saved the login page as index.html
, edited all the href=
and action=
fields to have the full URL to the Agile server.
我将登录页面另存为index.html
,编辑了所有href=
和action=
字段以获得 Agile 服务器的完整 URL。
The key <form>
line needed to change from
<form>
需要改变的关键线
<form autocomplete="off" name="MainForm" method="POST"
action="j_security_check"
onsubmit="return false;" target="_top">
to
到
<form autocomplete="off" name="MainForm" method="POST"
action="http://my.company.com:7001/Agile/default/j_security_check"
onsubmit="return false;" target="_top">
I also added this snippet to the end of the <body>
我还将此代码段添加到 <body>
<script>
function checkCookiesEnabled(){ return true; }
document.MainForm.j_username.value = "joeuser";
document.MainForm.j_password.value = "abcdef";
submitLoginForm();
</script>
I had to disable the cookie check by redefining the function that did the check, because I was hosting this from XAMPP and I didn't want to deal with it. The submitLoginForm()
call was inspired by inspecting the keyPressEvent()
function.
我不得不通过重新定义进行检查的函数来禁用 cookie 检查,因为我是从 XAMPP 托管它的,我不想处理它。该submitLoginForm()
调用的灵感来自于检查keyPressEvent()
函数。
回答by Muhammad_Daka
You can use Autohotkey
, download it from: http://ahkscript.org/download/
您可以使用Autohotkey
,从以下网址下载:http: //ahkscript.org/download/
After the installation, if you want to open Gmail website when you press Alt+g, you can do something like this:
安装后,如果你想在按下Alt+时打开 Gmail 网站g,你可以这样做:
!g::
Run www.gmail.com
return
Further reference: Hotkeys (Mouse, Joystick and Keyboard Shortcuts)
进一步参考:热键(鼠标、操纵杆和键盘快捷键)
回答by grd
Well, its true that we can use Vb Script for what you intended to do. We can open an application through the code like Internet Explorer. We can navigate to site you intend for. Later we can check the element names of Text Boxes which require username and password; can set then and then Login. It works fine all of using code.
好吧,我们确实可以使用 Vb Script 来完成您想要做的事情。我们可以通过像 Internet Explorer 这样的代码打开一个应用程序。我们可以导航到您打算访问的站点。稍后我们可以检查需要用户名和密码的文本框的元素名称;可以设置然后登录。它在所有使用代码中都能正常工作。
No manual interaction with the website. And eventually you will end up signing in by just double clicking the file.
无需与网站进行手动交互。最终,您只需双击该文件即可登录。
To get you started :
让你开始:
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("https://gmail.com")
This will open an instance of internet explore and navigate to gmail. Rest you can learn and apply.
这将打开一个 Internet explore 实例并导航到 gmail。休息你可以学习和应用。