从 yql 结果中检索 url

发布于 2024-10-05 15:58:59 字数 891 浏览 3 评论 0原文

我一直在尝试了解如何从 yql 结果返回链接,但到目前为止我得到的唯一东西是 [object Object] 并且到目前为止我没有得到任何结果,你能向我解释一下为什么会发生这种情况吗?我想要的只是将结果显示为链接。

<div id="funfacts"> 
</div> 
<script> 
function funfacts(o){ 
  var facts = document.getElementById('funfacts'); 
  if(facts){ 
    var data = o.query.results.a; 
    var out = document.createElement('a'); 
    out.className = 'fact'; 
    facts.appendChild(out); 
    out.innerHTML = data.join("<br />"); 
  } 
} 
</script> 
<script src="http://query.yahooapis.com/v1/public/yql?q=select%20href%20from%20html%20where%20url%3D'http%3A%2F%2Fcid-a59bebc211b678a6.office.live.com%2Fbrowse.aspx%2FPublic%2Fhi5'%20and%20xpath%3D'%2F%2Fa%5B%40id%3D%22download%22%5D'%0D%0A&format=json&diagnostics=true&callback=funfacts"></script> 

我希望这个例子足以理解,我想做的就是让它显示该页面的 url 列表,但是它只返回 [object Object] 行的列表。

I have been trying to understand how to return links from yql results, but so far the only thing im getting is [object Object] and i am not getting anywhere so far, could you care to explain to me why is this happening? All I want is to display the results as links.

<div id="funfacts"> 
</div> 
<script> 
function funfacts(o){ 
  var facts = document.getElementById('funfacts'); 
  if(facts){ 
    var data = o.query.results.a; 
    var out = document.createElement('a'); 
    out.className = 'fact'; 
    facts.appendChild(out); 
    out.innerHTML = data.join("<br />"); 
  } 
} 
</script> 
<script src="http://query.yahooapis.com/v1/public/yql?q=select%20href%20from%20html%20where%20url%3D'http%3A%2F%2Fcid-a59bebc211b678a6.office.live.com%2Fbrowse.aspx%2FPublic%2Fhi5'%20and%20xpath%3D'%2F%2Fa%5B%40id%3D%22download%22%5D'%0D%0A&format=json&diagnostics=true&callback=funfacts"></script> 

I hope this example is enough for understanding, all i am trying to do is for it to display the list of urls from that page, however it only returns a list of [object Object] lines.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疾风者 2024-10-12 15:58:59

如果您对返回对象执行 console.log,您将看到结果实际上是一个包含三个数组的数组。因此,要获取网址,您实际上需要执行类似 o.query.results.a[n].href 的

results: Object
a: Array[3]
0: Object
href: "http://public.blu.livefilestore.com/y1pXKbPqGSt2TkgDjLyAOoYLWSPBnYLdxVtOHoR4W0sERdCyCncGu4LR8Bg4e81W…"
__proto__: Object
1: Object
2: Object

操作,这是 jsfiddle

If you do a console.log on the return object you'll see that results is actually an array with three arrays within it. Thus to get the url you would actually need to do something like o.query.results.a[n].href

results: Object
a: Array[3]
0: Object
href: "http://public.blu.livefilestore.com/y1pXKbPqGSt2TkgDjLyAOoYLWSPBnYLdxVtOHoR4W0sERdCyCncGu4LR8Bg4e81W…"
__proto__: Object
1: Object
2: Object

Here is the jsfiddle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文