使用YQL和jQuery提取数据

Pulling data with YQL and jQuery

本文关键字:提取 数据 jQuery YQL 使用      更新时间:2023-09-26

我正在使用YQL从atlatlsoftware.com上的div中提取基本信息。我需要找到地址、电话号码和电子邮件。

我当前的代码转换YQL中的数据,并将其作为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);

通过在chrome控制台中键入atlatlInfo.responseJSON.query.results.td.div,我可以获得所需的数据。当我尝试执行console.log(atlatlInfo.responseJSON.query.results.td.div)时,我的chrome控制台会出现"未定义"。

如何使用javascript获取需要使用的数据?

$.getJSON返回异步结果;其中CCD_ 3被调用时可以不定义CCD_;请参阅如何从异步调用返回响应?。尝试利用jQuery.getJSON( url [, data ][, success ] )success回调处理调用$.getJSON 返回的data

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>