通过脚本自动登录网站

问题描述 投票:0回答:1

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

启动VPNGUI -c-用户1000 -pwd 123456

我需要JavaScript的帮助,该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脚本实现这一目标。

萨米人

javascript autologin
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.