我最近制作了一个程序,通知我游戏服务器是离线还是在线,但我认为我的程序有一个非常简单的版本。顺便说一句。该项目中关联的网站是
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 :(得分:0)
如果您的HTML总是那么简单,您应该只能调用`document.body.innerText'或'document.documentElement.textContent',具体取决于您的'浏览器'对象使用的引擎。
如果该站点是您的,您可能需要调整PHP以返回JSON或XML而不是HTML。 (XML有让您指定样式表的好处,因此相同的URL可以在浏览器和程序查询中使用。)