开发者

YQL select from xml

开发者 https://www.devze.com 2023-03-28 11:33 出处:网络
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.

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"

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.

Thanks.

UPDATE

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"

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.

UPDATE

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" 
开发者_如何学Go        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.


I think this may have to do with they way the xhtml is written and not the actual YQL statement.

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&nbsp; 22033<br/>
-----------^

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())
    }
})
0

精彩评论

暂无评论...
验证码 换一张
取 消