0

我有一个函数可以给我两个单词之间的文本:

Private Shared Function GetBetween(ByRef strSource As String, ByRef strStart As String, ByRef strEnd As String, Optional ByRef startPos As Integer = 0) As String
    Dim iPos As Integer, iEnd As Integer, lenStart As Integer = strStart.Length
    Dim strResult As String
    strResult = String.Empty
    iPos = strSource.IndexOf(strStart, startPos)
    iEnd = strSource.IndexOf(strEnd, iPos + lenStart)
    If iPos <> -1 AndAlso iEnd <> -1 Then
        strResult = strSource.Substring(iPos + lenStart, iEnd - (iPos + lenStart))
    End If
    Return strResult
End Function

所以我的html代码是:

<div class="upper-right-section">
            <div class="header-stats">


    <div class="stat-entry">
        <span class="stat-value">48998</span>
  <span class="stat-name">iscritti</span>

    </div>



    <div class="stat-entry">
        <span class="stat-value">22760801</span>
  <span class="stat-name">visualizzazioni video</span>

    </div>

  </div>

          <span class="valign-shim"></span>
        </div>

我有两次<span class="stat-value">,我想获得第二次比赛的价值,我该怎么办?谢谢,马特奥。

4

1 回答 1

1

对于一般的 html 解析,HAP 或 CSQuery 非常好,但是如果这是您程序中的一个孤立案例,并且您确信 html 源将保持不变,您可以使用以下内容:

Dim value As String = Split(Split(theHtmlStringHere, "<span class=""stat-value"">")(2), "</span>")(0)
于 2012-11-24T07:57:00.883 回答