0

我最近做了一个程序来通知我游戏服务器是离线还是在线,但我认为我的程序有一个非常简单的版本。顺便提一句。该项目关联的网站是

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

它返回 150 个玩家中的 n 个,(在线)等待和离线显示在页面和标题中。我知道如何通过使用获取网络文档的标题,document.Title但我只需要播放器的数量(n)而不是“150 个播放器”,如果服务器在线或离线,我还想播放声音文件(如果服务器在线,页面返回“n of 150 player”但(在线)等待被视为离线)

这是我的代码:

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>
4

1 回答 1

0

如果您的 HTML 总是那么简单,您应该可以只调用“document.body.innerText”或“document.documentElement.textContent”,具体取决于“浏览器”对象使用的引擎。

如果该站点是您的,您可能需要调整 PHP 以返回 JSON 或 XML 而不是 HTML。(XML 具有让您指定样式表的好处,因此相同的 URL 可以在浏览器和程序查询中工作。)

于 2013-05-18T14:25:58.050 回答