我在VB.NET中创建了一个简单的FORM,它需要一些细节,然后需要使用这些信息登录到3个位置。
目前我有代码所以从textBoxs获取这些数据并将它们分配给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 :(得分: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将数据输入网站时,此网站上有多个资源可能会为您提供更多信息。
希望这有帮助!