如何解析作为网络服务器响应返回的html内容,并在vb.net桌面应用程序的组合框中显示特定的标签值

发布于 2024-10-07 05:38:43 字数 2166 浏览 0 评论 0原文

我正在尝试使用 Httpwebrequest/response 从 Url 获取一些数据,我收到了在 msgbox 中显示的响应。它显示整个 HTML 内容。 现在我想获取特定标签(TD 标签)值并在 vb.net 桌面应用程序的组合框中显示其所有值。

我从网络服务器获取响应的代码是:

enter code here

Imports System.IO

Imports System.Net

Imports System.Xml

Imports System.Text.Encoder

公共类登录

Private Sub login_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    End
End Sub

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

End Sub

Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok.Click
    Dim strId As String = txt_uid.Text
    Dim strPwd As String = txt_pwd.Text
    Dim oEncoder As New System.Text.ASCIIEncoding
    Dim postData As String = "UM_username=" + strId
    postData += ("&UM_password=" + strPwd)


    Dim data As Byte() = oEncoder.GetBytes(postData)
    MsgBox(postData)




    Dim webStream As Stream

    Dim webResponse As String = ""

    Dim req As HttpWebRequest

    Dim res As HttpWebResponse
    Dim Output As String
    'Dim Posit1 As Int32
    'Dim Posit2 As Int32

  req = WebRequest.Create("http://localhost/basic_framework/index.php?menu=login&UM_email=" & strId & "&UM_password=" & strPwd)

req.ContentType = "application/x-www-form-urlencoded" req.KeepAlive = False 请求方法=“POST” res = req.GetResponse()

    webStream = res.GetResponseStream()

    Dim webStreamReader As New StreamReader(webStream)
    While webStreamReader.Peek >= 0
        Output = webStreamReader.ReadToEnd()
        RichTextBox1.Text = Output

Msgbox(Output)

    End While







End Sub

End Class

此代码从 url 获取响应并将其显示在 Richtextbox 或 msgbox 中 现在我想获取一个特定的标签值(例如,td、选项值)并动态地将其显示在我的 vb.net 应用程序表单的组合框中。需要解析 html 内容然后获取该标签值。请给我建议一个方法...... 如果需要解析,如何解析html内容以仅获取vb.net形式的组合框中的特定标记值

i am trying to fetch some data from Url using Httpwebrequest/response, i am getting response which i am showing in a msgbox. It show whole HTML contents.
Now my i want to fetch a specific tag(TD tag) value and show all its value in a combobox in vb.net desktop application.

my code to get response from webserver is :

enter code here

Imports System.IO

Imports System.Net

Imports System.Xml

Imports System.Text.Encoder

Public Class login

Private Sub login_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    End
End Sub

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

End Sub

Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok.Click
    Dim strId As String = txt_uid.Text
    Dim strPwd As String = txt_pwd.Text
    Dim oEncoder As New System.Text.ASCIIEncoding
    Dim postData As String = "UM_username=" + strId
    postData += ("&UM_password=" + strPwd)


    Dim data As Byte() = oEncoder.GetBytes(postData)
    MsgBox(postData)




    Dim webStream As Stream

    Dim webResponse As String = ""

    Dim req As HttpWebRequest

    Dim res As HttpWebResponse
    Dim Output As String
    'Dim Posit1 As Int32
    'Dim Posit2 As Int32

  req = WebRequest.Create("http://localhost/basic_framework/index.php?menu=login&UM_email=" & strId & "&UM_password=" & strPwd)

req.ContentType = "application/x-www-form-urlencoded"
req.KeepAlive = False
req.Method = "POST"
res = req.GetResponse()

    webStream = res.GetResponseStream()

    Dim webStreamReader As New StreamReader(webStream)
    While webStreamReader.Peek >= 0
        Output = webStreamReader.ReadToEnd()
        RichTextBox1.Text = Output

Msgbox(Output)

    End While







End Sub

End Class

this code get the response from url and show it in a richtextbox or msgbox
Now i want to get a specific tag value (say, td, option values) and show it in a combobox in my vb.net application form dynamically.It would be needed to parse html content then get that tag value . Please suggest me a way......

If parsing needed , how to parse html contents to get only specific tag value in a combobox in vb.net form

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月寒剑心 2024-10-14 05:38:43

好吧...如果您可以确定您的请求返回有效的 XHTML(实际上是 XML),您也许可以使用 XPath 表达式。

Well...if you can be sure that your request returns valid XHTML (which is XML indeed), you might be able to use an XPath expression.

命比纸薄 2024-10-14 05:38:43

对于最复杂的情​​况(例如,AJAX 网站等),您可以将 HTMLUnit 库与 iKVM 结合使用。

For the most complicated cases (e.g., an AJAX web-site, etc.) you could use HTMLUnit library with iKVM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文