gpt4 book ai didi

jquery - 使用jquery检索外部页面数据

转载 作者:行者123 更新时间:2023-12-01 07:35:35 25 4
gpt4 key购买 nike

我需要检索有关 ventrilo 服务器状态的信息。 ventrilo 的网站提供检索服务器信息的服务。例如,这是游戏竞技场 ventrilo 服务器:http://www.ventrilo.com/status.php?hostname=144.140.154.11&port=25000

我正在尝试获取“ channel 和用户信息”下的部分。但该表没有 id,并且页面上还有许多其他表。我怎样才能做到这一点?

我还听说某些浏览器不允许您加载外部内容。我该如何解决这个问题?

最佳答案

除了 Marc 的回答之外,您还可以使用 Yahoo 的 YQL 服务通过以下查询来检索表

select * from html where url="http://www.ventrilo.com/status.php?hostname=144.140.154.11&port=25000" and xpath='//center[4]/table'

然后,您可以将 YQL 结果与 jQuery 结合使用,在您的网站上显示该表,如以下演示所示。

工作演示

http://jsbin.com/eveka (可通过 http://jsbin.com/eveka/edit 编辑)

完整来源

JavaScript

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];
});
});

HTML

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

关于jquery - 使用jquery检索外部页面数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2171021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com