我正在研究一个通过浏览雅虎的YQL从外部网站获取所有<table>
元素的脚本。这近来运行良好,但从今天起停止运行。我不完全知道为什么,使用的所有网站,与此代码的工作:AJAX解析+雅虎YQL返回没有结果?
<script type="text/javascript">
$(document).ready(function() {
var container = $('#target');
function doAjax(url) {
if (url.match('^http')) {
$.getJSON("http://query.yahooapis.com/v1/public/yql?"
+ "q=select%20*%20from%20html%20where%20url%3D%22"
+ encodeURIComponent(url)
+ "%22&format=xml'&callback=?",
function (data) {
if (data.results[0]) {
var fullResponse = $(filterData(data.results[0])),
justTable = fullResponse.find("body");
container.append(justTable);
} else {
var errormsg = '<p>Error: could not load the page.</p>';
container.html(errormsg);
}
});
} else {
$('#target').load(url);
}
}
function filterData(data) {
data = data.replace(/<?\/body[^>]*>/g, '');
data = data.replace(/[\r|\n]+/g, '');
data = data.replace(/<--[\S\s]*?-->/g, '');
data = data.replace(/<noscript[^>]*>[\S\s]*?<\/noscript>/g, '');
data = data.replace(/<script[^>]*>[\S\s]*?<\/script>/g, '');
data = data.replace(/<script.*\/>/, '');
data = data.replace(/<img[^>]*>/g, '');
return data;
}
doAjax('http://www.google.com');
});
</script>
我改变该网址给Google,并改变了它找到<body>
标签,而不是<table>
标签,以便更好地显示其不工作。我查看了它请求的网址,但没有显示任何内容。不知道是什么问题。
以下[@yql](http://twitter.com/yql)在Twitter上很有帮助。它似乎没有很多短期中断,但如果还有更多的一般问题或升级,Twitter频道似乎是有帮助的。此外,您应该在此处标记自己的答案,以便将此问题标记为已完成。 – BrianC 2012-01-11 03:21:04