Использование VBA для входа - PullRequest
0 голосов
/ 28 июня 2019

Я хочу использовать vba для входа на сайт.Это облегчает задачу для всех, и не все должны знать пароль таким образом.Тем не менее, сайт был недавно обновлен, и теперь код, который я использовал (который был скотчен из кусочков и кусочков)

`Sub apiweb()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = "https://apiweb.biomerieux.com/login"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
Do
 ' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.document
HTMLDoc.all.login.Value = "xxxx"
HTMLDoc.all.Password.Value = "yyyy"
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub`

Так что раньше работало, что вы нажимаете кнопку в Excel, сайт будетоткрыть и через секунду или 2 логин и пароль появится, и вы просто нажмите логин.Теперь он только открывает сайт.

Я попробовал несколько вещей, включая проверку элементов, но я новичок, поэтому я не знаю, что искать или что делать.Так что любая помощь (и объяснение) будет принята с благодарностью!

Ответы [ 2 ]

0 голосов
/ 04 июля 2019

Как насчет этого метода?

Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub Login_2_Website()

Dim oHTML_Element As IHTMLElement
Dim sURL As String

On Error GoTo Err_Clear
sURL = "https://apiweb.biomerieux.com/login"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True

Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE

Set HTMLDoc = oBrowser.Document

HTMLDoc.all.signupEmail.Value = "signupEmail"
HTMLDoc.all.signupPassword.Value = "*****"

For Each oHTML_Element In HTMLDoc.getElementsByTagName("signupSubmit")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next

' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub

enter image description here

enter image description here

В сторону, нажмите F12, чтобы увидеть HTML за вашим браузером.

0 голосов
/ 28 июня 2019
Option Explicit

Sub WbClkMe()

Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButton As MSHTML.IHTMLElement

IE.Visible = True

IE.navigate "https://apiweb.biomerieux.com/login"

Do While IE.readyState <> READYSTATE_COMPLETE

Loop

Set HTMLDoc = IE.document

Set HTMLInput = HTMLDoc.getElementById("signupEmail") ' This is based on on your website

HTMLInput.Value = "" 'Put the value of Usernamae

Set HTMLInput = HTMLDoc.getElementById("signupPassword") 'This is based on on your website

HTMLInput.Value = "" 'Put the value of Password

Set HTMLButton = HTMLDoc.getElementById("signupSubmit") 'This is based on on your website

HTMLButton.Click


End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...