1
votes

Using the YQL console, I entered:

select * from htmlstring where url='finance.yahoo.com/q/op?s=PG'

And the display panel showed the raw html of the entire page as XML, which is what I wanted.

It gave me the REST Query at the bottom of the page as follows:

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20htmlstring%20where%20url%3D'finance.yahoo.com%2Fq%2Fop%3Fs%3DPG'&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

How can I put that url in a script (with or without jQuery) so that I get the same output in a string I can then parse?

I find nothing on the YQL pages that tells me how to do that, and all my attempts (with or without jQuery) have been unsuccessful.

The text I want is apparently somewhere in a returned object. How do I get at it?

1

1 Answers

0
votes

You can get along reading XML with basically three methods in JavaScript:

  1. ActiveX
  2. createDocument
  3. XmlHttpRequest

Here are some basic usage examples. Each creates an xmlDoc object, which you can use afterwards.

ActiveX:

var url = 'http://query.yahooapis.com/....';
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
while(xmlDoc.readyState != 4) {};
xmlDoc.load(url);
readXML();

createDocument:

var url = 'http://query.yahooapis.com/....';
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = readXML;
xmlDoc.load(url);

XMLHttpRequest

var url = 'http://query.yahooapis.com/....';
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, false);
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send("");
xmlDoc = xmlhttp.responseXML;
readXML();