2013-05-18 74 views
0

我最近做了一個程序來通知我遊戲服務器是離線還是在線,但我認爲我的程序有一個簡單的版本。順便說一句。在這個項目中相關的網站是如何在VB.NET中的div標籤內獲取文本

http://stats.teamextrememc.com/iframe_status.php

它返回的150名玩家N,(網上)等,以及脫機顯示在頁面上,並在標題。 我知道如何通過使用document.Title獲得網絡文檔的標題,但我只需要 數量的播放器(n)而不是「150個播放器」,並且如果服務器處於聯機或脫機狀態,我也想播放聲音文件(如果服務器在線,頁面返回「150名玩家N」但(在線)等被認爲是離線)

這是我的代碼:

Public Class Form1 
Private stat As String 
Private time As Integer 
Private DocTitle As String 
Private Onetime As Boolean = False 
Public Sub PlaySoundFile(ByVal SoundPath As String) 
    PlaySound.SoundLocation = SoundPath 
    PlaySound.Load() 
    PlaySound.Play() 
End Sub 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    refresher.Start() 

End Sub 
Private PlaySound As New System.Media.SoundPlayer 
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles refresher.Tick 
    DocTitle = browser.DocumentTitle 
    time += 1 
    Label1.Text = DocTitle 
    If time = 5 Then 
     browser.Refresh() 
     time = 0 
    End If 

    If DocTitle = "Offline" And Onetime = False Then 
     PlaySoundFile("C:/down.wav") 
     Onetime = True 
    ElseIf DocTitle <> "Offline" And Onetime = True Then 
     PlaySoundFile("C:/up.wav") 
     Onetime = False 
    End If 
End Sub 

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click 
End Sub 
End Class 

而這正是該頁面返回打開的時候它在瀏覽器中:

<!doctype html><html> 
<head> 
<title>150 of 150 players</title> 
<meta http-equiv="REFRESH" content="20"> 
<style> 
body { 
margin:0; padding:0; 
background-color:transparent; 
color:#66FF00; 
font-family: Verdana,Geneva,sans-serif; 
    font-size: 13px; 
    } 
#statuserr {color:#FF3636} 
.white { color: #EEE; font-size:11px } 
.dark { background-color:#333; font-size:24px } 
</style> 
</head> 
<body class=""> 
<div class="">150 of 150 players<br/></div> 
</body> 

回答

0

如果你的HTML總是那麼簡單,你應該能夠調用`document.body.innerText'或'document.documentElement.textContent',這取決於你的'瀏覽器'對象使用什麼引擎。

如果該網站是您的,您可能需要調整PHP以返回JSON或XML而不是HTML。 (XML有讓你指定樣式表的好處,所以相同的URL可以在瀏覽器和程序查詢中工作。)

相關問題