简体   繁体   English

使用VBA脚本登录网站登录页面

[英]Using a VBA script to login to a website Login Page

I am trying to use sources on google and on this site to help me but I am struggling to enter a username and password to a input box on a login page. 我正在尝试使用Google和此站点上的资源来帮助我,但我正在努力在登录页面的输入框中输入用户名和密码。

The page is on a local network on our work server. 该页面位于我们的工作服务器上的本地网络上。

The HTML code for the login page: 登录页面的HTML代码:

<TD background=/frontend/images/greenback.gif width=302><INPUT maxLength=32 name=username> </TD>

<TD background=/frontend/images/greenback.gif width=302><INPUT maxLength=32 type=password value="" name=password> </TD>

So far I have tried: 到目前为止,我已经尝试过:

Sub Test()

On Error Resume Next

Dim sUrl As String: sUrl = "https://workplace.plus.net/index.html?"
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

ie.navigate sUrl

Do While ie.readystate <> 4: DoEvents: Loop

ie.document.getElement.Name("username").Value = 1234

End Sub

I have also tried: 我也尝试过:

ie.document.getElement.Name("username").Value = 1234
ie.document.getElement.Id("username").Value = 1234
ie.document.getElement.Class("username").Value = 1234
ie.document.getElement.Type("username").Value = 1234

ie.document.getElementByClassName("username").Value = 1234
ie.document.getElementById("username").Value = 1234
ie.document.getElementByName("username").Value = 1234
ie.document.getElementByType("username").Value = 1234

The thing is I used this same code on google with the ID button and it works. 问题是我在Google上使用ID按钮使用了相同的代码,并且可以正常工作。 Is there something I am not taking into consideration? 有没有我没有考虑的东西?

Here i'm using the facebook login page. 在这里,我正在使用Facebook登录页面。 You can put any other link to login, put sUser as string and sPass as string. 您可以放置​​任何其他链接来登录,将sUser作为字符串,将sPass作为字符串。 Assigned the values you want to input. 分配要输入的值。 Application.Wait (Now + TimeValue("00:00:02")) is the time between loading the page and add login id and password. Application.Wait(Now + TimeValue(“ 00:00:02”))是加载页面与添加登录ID和密码之间的时间。 On the other hand will pass the user id and password IE.Document.all.Item("email").Value = sUser. 另一方面,将传递用户ID和密码IE.Document.all.Item(“ email”)。Value = sUser。 Try this code please 请尝试此代码

Sub facebookPost()
Dim IE As Object
Dim sUser As String, sPass As String


sUser = "1234"
sPass = "1234"

Set IE = CreateObject("INTERNETEXPLORER.Application")

IE.Navigate ("www.Facebook.com")
IE.Visible = True

Do While IE.Busy: DoEvents: Loop

Application.Wait (Now + TimeValue("00:00:02"))

IE.Document.all.Item("email").Value = sUser
IE.Document.all.Item("pass").Value = sPass
IE.Document.all.Item("loginbutton").Click
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM