2017-07-03 45 views
0

我在VB.NET中創建了一個簡單的FORM,它需要一些細節,然後需要使用此信息登錄到3個位置。從VB應用程序填充Web窗體

目前我有代碼,所以它從文本框中獲取這些數據並將它們分配給4個不同的變量。從那裏我也開闢了三個不同的網站。

我很難找到我將如何採取變量,然後在Web應用程序上填充相應的字段。有什麼建議麼?

我的代碼:

Public Class Form1 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     'Define Store variable 
     Dim Store As String 
     Store = Me.TextBox1.Text 
     'Define IP Address variable 
     Dim IPAddress As String 
     IPAddress = Me.TextBox2.Text 
     'Define Username variable 
     Dim Username As String 
     Username = Me.TextBox3.Text 
     'Define Password variable 
     Dim Password As String 
     Password = Me.TextBox4.Text 

     ' Open Store Specific URL 1 
     Dim WebAddress1 As String = "http://" & IPAddress & ":" 
     Process.Start(WebAddress1) 
     getElementByName 

     ' Open Store Specific URL 2 
     Dim WebAddress2 As String = "http://somedomain2.com" 
     Process.Start(WebAddress2) 

     ' Open Store Specific URL 3 
     Dim WebAddress3 As String = "http://somedomain3.com" 
     Process.Start(WebAddress3) 

    End Sub 
End Class 

回答

0

你需要做的是確定要填充的元素名稱。這通常可以通過轉到網頁來完成,然後按查看源代碼(通過網頁瀏覽器進行更改,有些您可以右鍵點擊,它將在那裏,一些您可以通過設置按鈕訪問)。源,你會想要找到你想發送信息的對象(通常是一個文本框或者這些行的一些東西)。通常這些框具有標題,如用戶名或密碼。因此,我建議您根據您在網站上可以看到的信息進行Ctrl + F搜索。我在你的代碼中看到你有GetElementByName,而這正是你要做的。您將要存儲

下面是一個例子代碼:

Dim IE As Object 'Internet explorer object 
Dim objCollection As Object 'Variable used for cycling through different elements 

'Create IE Object 
IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 
IE.Navigate("https://somewebsite.com/") 'Your website 

Do While IE.Busy 
    Application.DoEvents() 'This allows the site to load first 
Loop 

'Find the field you are looking for and store it into the objCollection variable 
objCollection = IE.document.getelementsbyname("CustomerInfo.AccountNumber") 'The "CustomerInfo.AccountNumber" is the name of the element I looked for in this case. 

'Call element, and set value equal to the data you have from your form 
objCollection(0).Value = MainForm.tbLoan.Text 

' Clean up 
IE = Nothing 
objCollection = Nothing 

這應該是一個良好的開端爲您服務。在使用vb.net將數據輸入網站時,本網站上有多種資源可能會爲您提供更多信息。

希望這有助於!

相關問題