0

好的,所以我正在开发一个程序,该程序可以读取网页并在页面有更新时弹出一个消息框。现在我的目标是登录网站并在我的程序中显示登录帐户的用户名

如何从welcome_user div 中获取文本?另外我如何检查welcome_user div是否在页面上,如果没有登录网站(我知道如何部分登录)

Html 示例:

<div id="usrpnl" style="float:right;">
     <div class="frm_login" style="text-align:right;">
          <div class="welcome_user"><b>Welcome (Username here)!</b></div>
     </div>
</div>

4

1 回答 1

0

尝试使用正则表达式来匹配用户名:

Imports System.Text.RegularExpressions

Public Class Form1

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

        '~~~ Sample HTML
        Dim strHtml As String = "<div id=""usrpnl"" style=""float:right;"">" & _
                                    "<div class=""frm_login"" style=""text-align:right;"">" & _
                                        "<div class=""welcome_user""><b>Welcome Akhilesh!</b></div>" & _
                                    "</div>" & _
                                "</div>"

        '~~~ Regular Expression to match the username from the HTML
        Dim m As Match = Regex.Match(strHtml, "Welcome\s(.*)!", RegexOptions.IgnoreCase)
        If m.Success Then   '~~~ if found...
            Dim strUsername As String = m.Groups(1).Value   '~~~ ...gets the matched username
            MessageBox.Show(strUsername)    '~~~ display it
        Else
            MessageBox.Show("Username not found !") '~~~ not found !
        End If

    End Sub
End Class

我希望这将有所帮助。祝你好运。

于 2012-08-22T10:58:52.533 回答