Login automatically to https html website

Bjorn

New member
Joined
Jun 8, 2016
Messages
2
Programming Experience
5-10
Hello,

I have to create a tool base on HttpWebRequest and HttpWebResponse but first I need to go automatically true the login page.
https://www.watchmyhome.de/index.html

the code is based on <form> and <input type="text" and <input type ="password"

<form id="datacenter-login-form" action="/login" method="post"><div class="ym-form linearize-form ym-columnar"><div class="ym-fbox">
<input type="text" name="Kennung" id="datacenter-username" placeholder="Username" /></div><div class="ym-fbox">
<input type="password" name="Passwort" id="datacenter-password" placeholder="Password" />
<input class="hidden" name="language" value="" /><script type="text/javascript"> var currentPageLanguage = 'en';
</script></div><div class="ym-fbox-footer ym-fbox-button"><span class="float-left" style="line-height:3.2rem">
</span><button id="login_submit" class="ym-button float-right" type="submit">Login</button></div></div></form>

I hope somebody can help me with this.

regards,
Bjorn
 

Bjorn

New member
Joined
Jun 8, 2016
Messages
2
Programming Experience
5-10
Ok I found the answer I was able to login, afterwards I can select the data I need from the source code with "Me.TextBox1.Text = Me.WebBrowser1.DocumentText"

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("id").ToString
If controlName = "datacenter-username" Then
curElement.SetAttribute("Value", "my_username")
End If
Next

theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("id").ToString
If controlName = "datacenter-password" Then
curElement.SetAttribute("Value", "my_password")
End If
Next
theElementCollection = WebBrowser1.Document.GetElementsByTagName("button")
For Each curElement As HtmlElement In theElementCollection
'If curElement.GetAttribute("value").Equals("login") Then
'curElement.InvokeMember("click")
'Javascript has a click method for we need to invoke on the current submit button element.
'End If
Dim controlName As String = curElement.GetAttribute("id").ToString
If controlName = "login_submit" Then
curElement.InvokeMember("click")
End If
Next

End Sub
 

kriszty

New member
Joined
Apr 4, 2016
Messages
4
Programming Experience
10+
I made this for our security camera website., it,s plain and simpel
it automatic login at the site
==============================

Imports System.Runtime.InteropServices
Public Class Form1

Private Property pageready As Boolean = False

#Region "Page Loading Functions"
Private Sub WaitForPageLoad()
AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
While Not pageready
Application.DoEvents()
End While
pageready = False
End Sub

Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
pageready = True
RemoveHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
End If
End Sub
#End Region

Dim drag As Boolean = False
Dim mousex As Integer, mousey As Integer

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
drag = True
mousex = Windows.Forms.Cursor.Position.X - Me.Left
mousey = Windows.Forms.Cursor.Position.Y - Me.Top
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If drag Then
Me.Left = Windows.Forms.Cursor.Position.X - mousex
Me.Top = Windows.Forms.Cursor.Position.Y - mousey
End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

WebBrowser1.Navigate("http://172.25.14.6")
WaitForPageLoad()

WebBrowser1.Document.GetElementById("username").SetAttribute("value", "admin")
WebBrowser1.Document.GetElementById("password").SetAttribute("value", "admin")
WebBrowser1.Document.GetElementById("b_login").InvokeMember("click")


End Sub

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Application.Exit()
End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
drag = True

End Sub

End Class
 
Top Bottom