通过脚本自动登录网站

Make automatic login to website via script

本文关键字:登录 网站 脚本      更新时间:2023-09-26

我有一个批处理文件,其中有用户名和密码,以以下格式登录网站行号16.5行第5个字是用户名,第7个字是密码。

start VPNGUI -c -user 1000 -pwd 123456

我需要一个关于JavaScript的帮助,它应该打开网站的主页,读取批处理文件收集用户名和密码,在主页上自动填写用户名和密码,并使用发送密钥登录。我尝试过使用vbscript,下面是我的代码,但我需要这个在Java中,应该允许用户自动登录到网站上一个点击。

VBScript: -

Dim username
Dim password
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:'Autoconnect'connect.bat", ForReading)
For i = 1 to 15
    objTextFile.ReadLine
Next
strLine = objTextFile.ReadLine
segments = Split(strLine," ")
username = segments(5)
pwd = Split(strLine," ")
password= pwd(7)
objTextFile.Close
set WshShell = WScript.CreateObject("WScript.Shell")
call WshShell.Run("https://mywebsite.com", 1, false) 'This will open your default browser
WScript.Sleep 5000
WshShell.SendKeys username 
WScript.Sleep 1000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys password
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Quit()

谁能建议我如何使用Java Script实现这一点。

萨米。

如果你想在一个网站上使用JavaScript,让它一键登录到另一个网站,这是不可能的,因为你不能跨域提交表单。