我需要检索有关ventrilo服务器状态的信息。 ventrilo的网站提供检索服务器信息的服务。例如,这是游戏竞技场ventrilo服务器:http://www.ventrilo.com/status.php?hostname=144.140.154.11&port=25000用jquery检索外部页面数据
我试图抓住“频道和用户信息”部分。但该表没有标识,页面上还有许多其他表。我该如何去做这件事?
我还听说有些浏览器不允许您加载外部内容。我怎么能解决这个问题?
我需要检索有关ventrilo服务器状态的信息。 ventrilo的网站提供检索服务器信息的服务。例如,这是游戏竞技场ventrilo服务器:http://www.ventrilo.com/status.php?hostname=144.140.154.11&port=25000用jquery检索外部页面数据
我试图抓住“频道和用户信息”部分。但该表没有标识,页面上还有许多其他表。我该如何去做这件事?
我还听说有些浏览器不允许您加载外部内容。我怎么能解决这个问题?
除了马克的回答,您可以使用雅虎的YQL服务与下面的查询检索表
select * from html where url="http://www.ventrilo.com/status.php?hostname=144.140.154.11&port=25000" and xpath='//center[4]/table'
然后,您可以使用与jQuery的YQL结果显示在显示在你的网站上的表格下面的演示。
http://jsbin.com/eveka(编辑通过http://jsbin.com/eveka/edit)
var
ventriloStatus = $('#ventriloStatus'),
hostname = '144.140.154.11',
port = 25000,
ventriloURL = 'http://www.ventrilo.com/status.php?hostname=' + hostname + '&port=' + port,
yqlURL = 'http://query.yahooapis.com/v1/public/yql?callback=?',
xpath = '//center[4]/table',
query = 'select * from html where url="' + ventriloURL + '" and xpath="' + xpath + '"'
data = {
q: query,
format: 'xml',
diagnostics: false
};
ventriloStatus.text('Loading...');
$.getJSON(yqlURL, data, function (response) {
ventriloStatus.html(response.results[0]).find('img').each(function() {
this.src = 'http://www.ventrilo.com/' + this.src.split('/').slice(-1)[0];
});
});
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Ventrilo with YQL</title>
<style>
body { font: 8pt sans-serif; }
p { display: inline; }
#ventriloStatus{ width: 600px; }
</style>
</head>
<body>
<h1>Ventrilo Status</h1>
<div id="ventriloStatus"></div>
</body>
</html>
两种方式:
1)如果有一个JSON的服务,您可以使用JSONP(检查谷歌,但我个人不喜欢这个)
2)如果您的服务器端使用PHP,取看看PHPQuery,在脚本中执行服务器端的抓取操作,然后在AJAX中调用该脚本来获取提取的数据(您可能希望实现某种级别的缓存,因为您使用的是网关... APC将是友好的工具)。
您有权访问服务器端脚本语言,还是想在客户端执行此操作? – brianpeiris 2010-01-31 09:03:33