0

Javascript FireFox extension (new user)

Hello guys,

I am writing to request help with using YQL within a firefox entension.

My aim is to select the html from a webpage and return it into an xml file whenever the user changes webpage.

Currently, i have tried various tutorials and samples i've found lying aorund the internet, none of them have worked for me so far.

For example, i am running the query "Select * from html where url ='bbc.co.uk'.

I need this returned into an xml file which i can parse within the javascript.

So far, most my code has boiled down to whatever I have found lying on google searches and of course the yahoo samples.e.g.

var q = y.query("Select * from html where url = 'bbc.co.uk');
var results = q.results;

All i need is a returned XML file which i can parse myself and add to a local database. I do not need Open Data tables either ( i think!).

Any advice or help is appreciated.

Thankyou in advance!

by
3 Replies
  • QUOTE (James @ Mar 18 2010, 02:10 PM) <{POST_SNAPBACK}>
    For example, i am running the query "Select * from html where url ='bbc.co.uk'.

    I need this returned into an xml file which i can parse within the javascript.
    ...
    All i need is a returned XML file which i can parse myself and add to a local database. I do not need Open Data tables either ( i think!).

    Any advice or help is appreciated.

    Thankyou in advance!


    Use the REST URL returned in the console for your use. For example, for the query that you provided

    CODE
    [balajin@visitbadfree-lm ~] $ curl -I "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http%3A%2F%2Fbbc.co.uk'%20&format=xml"
    HTTP/1.1 200 OK
    Date: Fri, 19 Mar 2010 14:26:46 GMT
    P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    Access-Control-Allow-Origin: *
    Cache-Control: public, max-age=0
    Content-Length: 49320
    Content-Type: text/xml;charset=utf-8
    Age: 4
    Connection: keep-alive
    Server: YTS/1.17.21


    The response is text/xml which you can parse the way you want. Also read http://developer.yahoo.com/yql/guide/yql_url.html for more info.
    0
  • The following code works in ASP.NET but we cannot transfer this into our javascript ADD-ON for Firefox 3.6.




    <script type="text/javascript">
    function handleResponse(json) {
    var results = json.results,
    ul = document.getElementsByTagName('ul')[0],
    li = null;
    for (var i = 0; i < results.length; i++) {
    li = document.createElement('li');
    li.innerHTML = results[i];
    alert(results[i]);
    ul.appendChild(li);
    }
    }
    </script>
    <script src="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fbbc.co.uk%22%20and%20xpath%3D%22//img%22&format=xml&diagnostics=false&callback=handleResponse"></script>



    We borrowed this code form somewhere else.

    We cannot transfer this accross to our Addon.

    Help appreciated!
    Cheers!
    0
  • You'll need to set "format=json" in your request. For example:
    CODE
    http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fbbc.co.uk%22%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2Fimg'&callback=handleResponse&format=json


    The one you're using has "format=xml", which is not what the callback fn is expecting.

    I didn't check the functionality of handleResponse(), or the firefox add-on docs, so you might need to make other changes as well.
    0

Recent Posts

in YQL