YQL 从 xml 中选择 [英] YQL select from xml
问题描述
我正在使用 YQL 控制台运行以下查询:
I'm using the YQL console to run the following query:
select *
from xml
where url="http://www.inova.org/patient-and-visitor-information/facilities/inova-fair-oaks-hospital/plan-your-visit/index.jsp"
and itemPath="html.body.form"
没有返回任何结果.我也试过使用 xpath
和 css
只是为了咧嘴笑,但我没有得到任何结果.如果我删除第二个过滤器,我会得到页面标记.难道我做错了什么?这是一个 XHTML 页面(根据文档类型),因此 select * from html
不起作用.
No results are returned. I've also tried using xpath
and css
just for grins, but I get no results. If I remove the second filter, I get the page markup. Am I doing something wrong? It's an XHTML page (according to the doctype), so select * from html
didn't work.
谢谢.
更新
我已将查询语法更新为一个似乎至少能返回结果的查询,但我需要更深入地研究.我真正需要的是这样的:
I've updated my query syntax to the one query that seems to at least return results, but I need to dive deeper. What I really need to get to is something like this:
select *
from xml
where url="http://www.inova.org/patient-and-visitor-information/facilities/inova-fair-oaks-hospital/plan-your-visit/index.jsp"
and itemPath="html.body.form.div#wrapper.div#page.div#content"
不幸的是,通过 id 访问特定 div 的语法不起作用,我还没有找到任何方法来到达返回的目标 div(带有 id="content"
的那个)任何结果.
Unfortunately, that syntax for accessing a specific div by id doesn't work and I haven't found any way of reaching that target div (the one with id="content"
) that returns any results at all.
更新
我偶然发现了,我的意思是偶然发现一个有效的 YQL 查询(目前,让我们忽略它有多脆弱):
I've stumbled, and I do mean stumbled onto a YQL query that works (for the moment, let's disregard just how brittle it is):
select *
from xml
where url="http://www.inova.org/patient-and-visitor-information/facilities/inova-fair-oaks-hospital/plan-your-visit/index.jsp"
and itemPath="html.body.form.div.1.div.4.div.2"
任何关于使其不那么脆弱(最好是防弹)的建议都非常非常感谢.
Any suggestions for a way to make it less brittle (and ideally bulletproof) would be really, really appreciated.
推荐答案
我认为这可能与他们编写 xhtml 的方式有关,而不是实际的 YQL 语句.
I think this may have to do with they way the xhtml is written and not the actual YQL statement.
Firefox 在尝试直接访问 YQL 语句时抛出此错误:
Firefox throws this error when trying to access the YQL statement direct:
XML Parsing Error: undefined entity
Location:http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%27http%3A%2F%2Fwww.inova.org%2Fpatient-and-visitor-information%2Ffacilities%2Finova-fair-oaks-hospital%2Fplan-your-visit%2Findex.jsp%27
Line Number 307, Column 12:
Fairfax, VA 22033<br/>
-----------^
如果您使用的是 jQuery,您可以通过以下方式绕过它:
If you are using jQuery you can get around it with something along these lines:
$.ajax({
type : 'GET',
dataType : 'xml',
url : 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fwww.inova.org%2Fpatient-and-visitor-information%2Ffacilities%2Finova-fair-oaks-hospital%2Fplan-your-visit%2Findex.jsp%22',
success : function(xhtml) {
//find all nodes
$(xhtml).find('h1').each(function(){
console.log($(this).html())
});
//target specific node
console.log($('#content').html())
}
})
这篇关于YQL 从 xml 中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!