Realize web page automatic login

Because the actual project comes into contact with the need for automatic login of a web page, record the process from learning to realization, for future reference, and also as a reference for everyone.

solved problem

Realize automatic webpage login, no need to repeatedly enter the password every time

method

Using the vbs script that comes with Windows, it can be realized with a few simple lines of code.

Implementation code

Paste the following code into a blank txt file, delete the # sign and the following comments, save, modify the suffix name to vbs, and modify it according to the ID on the website you need, if the last line reports an error, delete the last line to achieve automatic filling Account number and password.

Dim username,password,IE
username = "aaaaaaaa"  # 你的用户名
password = "bbbbbbbb"  # 你的密码
Set IE =CreateObject("InternetExplorer.Application")
ie.FullScreen=0
IE.Visible = True
IE.Navigate "www.baidu.com"  # 网址
Do while IE.ReadyState<> 4 or IE.busy
wscript.sleep 2000 
loop
IE.document.querySelector("#userNameInput").value=username  # 注意,这里面的"#userNameInput"是你需要自动登录网站上‘用户名’的ID
IE.document.querySelector("#userPwdInput").value=password  # "#userPwdInput"是你需要自动登录网站上 ‘密码’ 的ID
IE.document.querySelector("#logonBtn").onclick  # "#logonBtn"是你需要自动登录网站上‘登录’按钮的ID

Replenish

The login logic of different URLs is different. You need to click on the URL yourself, then press F12 to view the source code, and find the corresponding ID (click the button pointed by my arrow, and then click the login module, you can directly find the login module source code), and modify the code as needed, and different computers may have different errors due to different versions of IE browsers. I do not have the line IE.document.querySelector("#logonBtn").onclick in the above code (to achieve login), I only have to automatically fill in the account number and password. I don’t know why my computer will report an error on onclick.

But in the end, it can automatically fill in the account number and password, which can be regarded as fulfilling the requirements, saving the need to enter the account password every time.

insert image description here

Guess you like

Origin blog.csdn.net/weixin_44312422/article/details/116495237