Vb.net - 从网站获取时间

时间:2014-12-21 16:09:15

标签: vb.net time

"41:25"是时间,而且不断变化。

<div class="game-time">
<span class="elapsed j-elapsed" data-game-time="1419174626">41:25</span>

我尝试了这个但没有奏效:

 Private Sub Button2_Click(sender As Object, e As EventArgs)
    For Each h As HtmlElement In WebBrowser1.Document.GetElementsByTagName("span")
        If Not Object.ReferenceEquals(h.GetAttribute("className"), Nothing) AndAlso h.GetAttribute("className").Equals("elapsed j-elapsed") Then
            Label6.Text = h.InnerHtml
        End If
    Next
End Sub

我也试过这段代码:

Private Sub Button2_Click(sender As Object, e As EventArgs)
    Dim theElementCollection9 As HtmlElementCollection = Nothing
    theElementCollection9 = WebBrowser1.Document.GetElementsByTagName("div")
    For Each curElement9 As HtmlElement In theElementCollection9
        If InStr(curElement9.GetAttribute("className").ToString, "game-time") Then
            Label6.Text = curElement9.InnerText
        End If
    Next
End Sub

我需要一个答案。

1 个答案:

答案 0 :(得分:0)

直接摘自w3schools

添加此代码,您应该在路上。

var myVar=setInterval(function(){myTimer()},1000);
function myTimer(){
var d = new Date();
document.getElementById("myTimeElement").innerHTML = d.toLocaleTimeString();
}

这将每秒更新一次。你也可以像Plutonix建议的那样去看This link about asking questions