定制YQL的输出

发布于 2024-09-11 00:30:21 字数 624 浏览 2 评论 0 原文

此 YQL 语句(在 YQL 控制台中执行)从 TMDB 网站挑选电影的名称和年份。

select content from html where url="http://www.themoviedb.org/movie/27205" and xpath='//h3[@id="year"]|//h2[@id="title"]/a'

结果像这样返回:

"results": {
  "a": "Inception",
  "h3": "(2010)"
}

是否有任何简单的方法可以将结果标记为“名称”和“年份”而不是从中获取的 html 元素?

干杯!

This YQL statement (execute in the YQL console) picks out the name and year of a film from the TMDB website.

select content from html where url="http://www.themoviedb.org/movie/27205" and xpath='//h3[@id="year"]|//h2[@id="title"]/a'

the results come back like this:

"results": {
  "a": "Inception",
  "h3": "(2010)"
}

Is there any easy way to have label the results as 'name' and 'year' rather than the html elements they were grabbed from?

Cheers!

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

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

发布评论

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

评论(1

山川志 2024-09-18 00:30:21

目前没有简单的方法来快速为返回的标签添加别名。目前最好的方法是创建一个自定义数据表,它使您查询TMDB并转换结果(使用Javascript,位于 < /a> block) 到你想要的任何东西。

例如,我为您创建了一个快速自定义表格,该表格返回带有您选择的标签(nameyear)的结果。它还删除了年份周围的括号。要对其进行测试运行,请使用:

use "store://github.com/tmdb-jp" as tmdb;
select * from tmdb where movieid="27205"

生成的 JSON 具有以下结构(在通常的 YQL 响应内):

"movie": {
 "title": "Inception",
 "year": "2010"
}

如果您想尝试自己创建数据表,或者只是看看所涉及的内容,那么源就在我的 github。另外(这可能很有用)您可以一次查询多部电影:

use "store://github.com/tmdb-jp" as tmdb;
select * from tmdb where movieid in ("27205","9802")

PS store:// URL 只是意味着数据表存储在 Yahoo! 的“云”中为了速度和可靠性。您当然可以使用普通的 http:// URL(例如 github URL)。

Currently there is no easy way to quickly alias the returned labels. The best way at the moment is to create a custom data table which makes your query to TMDB and transforms the result (with Javascript, in an <execute> block) to whatever you want it to be.

For example, I created a quick custom table for you which returns the results with your labels of choice (name and year). It also removes the parentheses from around the year. To give it a test run, use:

use "store://github.com/tmdb-jp" as tmdb;
select * from tmdb where movieid="27205"

With the resulting JSON having the following structure (within the usual YQL response):

"movie": {
 "title": "Inception",
 "year": "2010"
}

If you want to have a go at creating a data table yourself, or just see what's involved, then the source is on my github. Also (it might be useful) you can query for multiple movies at once:

use "store://github.com/tmdb-jp" as tmdb;
select * from tmdb where movieid in ("27205","9802")

P.S. The store:// URLs just mean that the data table is being stored in Yahoo!'s "cloud" for speed and reliability. You can of course use a normal http:// URL (e.g. by github one) instead.

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