我在VB.NET中创建了一个简单的表单,其中包含了一些细节,然后需要使用这些信息登录到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发布于 2017-07-03 16:38:21
您需要做的是标识要填充的元素名。这通常可以通过转到网页,然后按下“查看源”(通过web浏览器进行更改,一些您可以右键单击,它就在那里,有些您可以通过“设置”按钮访问)。
查看源代码后,您将希望找到要发送信息的对象(通常是文本框或类似的内容)。通常这些框都有标题,如用户名或密码。因此,我建议做一个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将数据输入到网站时,可能会为您提供更多信息。
希望这能帮上忙!
https://stackoverflow.com/questions/44890181
复制相似问题