如何实现YQL分页?

发布于 2024-08-26 05:13:05 字数 856 浏览 9 评论 0 原文

我已阅读 YQL 指南,并不断查看 http: //developer.yahoo.com/yql/guide/yql-o...entables-paging 我一直在查看一些示例,但我仍然对 YQL 分页的工作原理感到非常困惑。

我试图解决的问题是为 Mozilla 实验室 Jetpack Gallery 的 jetpacks 页面创建一个 YQL 开放数据表 http:/ /jetpackgallery.mozillalabs.com/jetpacks

您可以使用 ?page 查询变量翻阅 jetpack 的页面,并且有一个 order_by 查询变量。每页只能看到 10 个结果。

问题:

  • 列表项
  • 我应该使用 or 吗?
    • 如何指定指示页面的查询参数?在本例中,它是“page”查询参数。
  • 我假设我应该使用: http://jetpackgallery.mozillalabs.com/jetpacks 这是正确的吗?
  • 在执行元素中,我需要提取页面上每个喷气背包的详细信息?如果是这样,我将如何为response.object 组织它?

有人可以提供一些帮助吗?或者也许指向我可以查看作为参考的数据表?或者关于分页如何工作的更好的文档?

I've read the YQL guide, and I keep reviewing http://developer.yahoo.com/yql/guide/yql-o...entables-paging and I have been looking at a few examples, but I'm still left pretty confused how YQL paging works.

The problem that I am trying to tackle is creating a YQL open data table for the Mozilla labs Jetpack Gallery's jetpacks pages http://jetpackgallery.mozillalabs.com/jetpacks

You flip through the pages of jetpacks with the ?page query variable and there is an order_by query variable. You can only see 10 results per page.

Questions:

  • List item
  • Should I use or ?
    • How do I specify the query parameter that indicates the page? in this case it is the 'page' query parameter.
  • I am assuming I should use: <urls><url>http://jetpackgallery.mozillalabs.com/jetpacks</url></urls> is this correct?
  • In the execute element, I will need to extract the details for each jetpack on the page? if so how would I organize that for the response.object?

Can anyone provide some help? or perhaps point to a data table that I can look at as a reference? or better documentation on how paging works?

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

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

发布评论

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

评论(1

骷髅 2024-09-02 05:13:05

首先,您应该查看 分页模型 (你的链接在上面被压缩了,所以我只是把它放在这里。

当你使用没有指定 块的分页时,它将被使用在 中指定 URL 的查询字符串中,只需使用 Flickr 照片搜索示例,您必须在打开诊断的情况下在控制台中运行它才能查看URL 中的变化。 id 属性用于在查询中插入数字,这里只是为了说明,分页部分如下所示:

   <paging model="page">  
     <start id="page" default="0" />  
     <pagesize id="per_page" max="250" />  
     <total default="10" />  
   </paging>  

例如,查询

select * from flickr.photos.search(10,20) where has_geo="true"`

使用的 URL 是 http。 ://api.flickr.com/services/rest/?method=flickr.photos.search&has_geo=true&page=1&per_page=30。正如您所看到的,它实际上采用了 page=1 但要求 per_page=30 并在内部截断了前 10 个结果,以便您获得偏移量 10 和总计共 20 个结果。
YQL之所以这么做,是因为选择的模型是page

另一个例子,如果您尝试执行此操作:

select * from flickr.photos.search(249,2) where has_geo="true"

YQL 将检索 ...&page=1&per_page=250...&page=2&per_page=250< /code> (为了说明起见,我缩短了网址) 按预期获得结果。

如果您在 部分中使用 JavaScript,则分页变量也会在全局范围内定义。您可以看到它在 flickr 中使用。 photos.astro OpenData 表

我想这应该回答你的问题,因为我看到 在 GitHub 上,您一直在研究如何使用 XPath 提取页面。

对于您的情况,您应该有类似的内容:

   <paging model="page">  
     <start id="page" default="1" />  
     <pagesize id="per_page" max="10" />  
     <total default="10" />  
   </paging>  

per_page 将位于您的内部查询中,但它用于 YQL 来确定所需的查询。然后在你的 JavaScript 中可能会做类似的事情:

   y.query(
       "select * from html where url=@url",
       {url: "http://jetpackgallery.mozillalabs.com/jetpacks?page=" + page}
       );

Firstly, you should be looking at the paging model (Your link got compressed above, so I'm just putting it here.

When you use the paging with no <execute></execute> block specified, it will be used in the query string with the URL specified in <url></url>. Just play with the Flickr Photo Search Example, you have to run it in the Console with Diagnostics turned on to look at the changes in the URL. The id attribute is used to insert the number in the query. Just to illustrate here, the paging portion looks like this:

   <paging model="page">  
     <start id="page" default="0" />  
     <pagesize id="per_page" max="250" />  
     <total default="10" />  
   </paging>  

For example, querying

select * from flickr.photos.search(10,20) where has_geo="true"`

The URL used was http://api.flickr.com/services/rest/?method=flickr.photos.search&has_geo=true&page=1&per_page=30. As you can see, it actually took the page=1 but asked for per_page=30 and internally truncated the first 10 results so that you get an offset of 10 and a total of 20 results.
The reason why YQL did this is because the model selected is page.

Another example, if you attempt to do this:

select * from flickr.photos.search(249,2) where has_geo="true"

YQL will retrieve both ...&page=1&per_page=250 and ...&page=2&per_page=250 (I've shortened the urls for illustration) as expected to get the results.

The paging variables are also defined in the global scope if you use JavaScript in <execute></execute> section. You can see this being used in the flickr.photos.astro OpenData Table.

I guess that should answer the question for you, since I see that on GitHub, you have been working on how to extract the pages using XPath.

For your case you should have something like:

   <paging model="page">  
     <start id="page" default="1" />  
     <pagesize id="per_page" max="10" />  
     <total default="10" />  
   </paging>  

The per_page would be in your internal query but it's used for the YQL to determine the queries needed. Then in your JavaScript could probably do something like:

   y.query(
       "select * from html where url=@url",
       {url: "http://jetpackgallery.mozillalabs.com/jetpacks?page=" + page}
       );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文