2

I am using YQL to pull basic information from a div on atlatlsoftware.com. I need to find the address,phone number, and email.

My current code turns the data from YQL and logs it in the console as JSON.

var atlatlInfo = $.getJSON("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fatlatlsoftware.com%22%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2F*%5B%40id%3D%22desktop-footer%22%5D%2Fdiv%5B3%5D%2Fdiv%2Ftable%2Ftbody%2Ftr%5B2%5D%2Ftd%5B1%5D'&format=json&diagnostics=true&callback=");

console.log(atlatlInfo);

By typing atlatlInfo.responseJSON.query.results.td.div in chrome console, i can get to the data I need. When i try to do console.log(atlatlInfo.responseJSON.query.results.td.div) my chrome console comes up with "undefined".

How do i get to the data i need to use, with javascript?

aelevy44
  • 37
  • 6

1 Answers1

0

$.getJSON returns an asynchronous result ; where atlatlInfo may not be defined when console.log(atlatlInfo); called ; see How do I return the response from an asynchronous call?. Try utilizing success callback of jQuery.getJSON( url [, data ][, success ] ) to process data returned by call to $.getJSON

var atlatlInfo = $.getJSON("https://query.yahooapis.com/v1/public/yql?" 
                           + "q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fatlatlsoftware.com%22%20and%0A%20%20%20%20%20%20xpath%3D" 
                           + "'%2F%2F*%5B%40id%3D%22desktop-footer%22%5D%2Fdiv%5B3%5D%2Fdiv%2Ftable%2Ftbody%2Ftr%5B2%5D%2Ftd%5B1%5D'" 
                           + "&format=json&diagnostics=true&callback="
                             // process results from asynchronous call here
                           , function success(data) {
                               // do stuff with results
                               console.log(data.query.results.td.div);
                 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177