如何使用 Yahoo 的 Answer API 对 YQL 中的字符进行转义?

发布于 2024-12-27 23:14:50 字数 803 浏览 6 评论 0原文

我通过 YQL 使用雅虎的 Answer API。我的查询是“如何烹饪培根”,我需要包含双引号,因为这确实匹配,您可以看到结果在基于网络的搜索中有所不同:

http://answers.yahoo.com/search/search_result;_ylt=Av2RD2lUBAad6J5WYYTma6gjzKIX;_ylv=3?p=%22how+to+cook+bacon%22

vs

http://answers.yahoo.com/search/search_result;_ylt=Av2RD2lUBAad6J5WYYTma6gjzKIX;_ylv=3?p=how+to+cook+bacon

问题是我无法转义我尝试过的字符 \" 并尝试包含 %22。只是想知道是否还有其他可行的方法?

这是我的不带引号的示例查询:

http://developer.yahoo.com/yql/console/?_uiFocus=answers&q=select%20*%20from%20answers.search%20where%20query%3D%22cars%22%20and%20category_id%3D2115500137%20and%20type%3D%22resolved%22#h=select%20*%20from%20answers.search%20where%20query%3D%22how%20to%20cook%20bacon%22%20and%20type%3D%22resolved%22

I'm using Yahoo's Answer API via YQL. My query is "how to cook bacon" and I need to include the double quotes because this does an exact match, you can see the results differ in their web based search:

http://answers.yahoo.com/search/search_result;_ylt=Av2RD2lUBAad6J5WYYTma6gjzKIX;_ylv=3?p=%22how+to+cook+bacon%22

vs

http://answers.yahoo.com/search/search_result;_ylt=Av2RD2lUBAad6J5WYYTma6gjzKIX;_ylv=3?p=how+to+cook+bacon

The problem is I can't escape characters I tried \" and tried including %22. Was just wondering if there was another method that would work?

Here's my example query without quotes:

http://developer.yahoo.com/yql/console/?_uiFocus=answers&q=select%20*%20from%20answers.search%20where%20query%3D%22cars%22%20and%20category_id%3D2115500137%20and%20type%3D%22resolved%22#h=select%20*%20from%20answers.search%20where%20query%3D%22how%20to%20cook%20bacon%22%20and%20type%3D%22resolved%22

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

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

发布评论

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

评论(2

穿透光 2025-01-03 23:14:50

我认为 Josh 的答案对于在通过 YQL 时引用或转义答案查询的原始问题是正确的。但是,进一步研究这个问题,我认为真正的问题是尝试通过 Answers API 复制 Answers UI 结果(反过来由 YQL 读取)。

问答网站。我认为区别在于排序顺序,但这似乎在 API 中不可用。

作为替代方案,您可以使用 Answers RSS 源并通过 YQL 处理它们:

  1. 转至answers.yahoo.com 并输入示例搜索 “如何煮培根”
  2. 在结果页面上,抓取左侧导航栏上的 RSS 链接 (示例)
  3. 将 RSS 链接与 YQL“feed”模块一起使用:从 url='http://answers.yahoo.com/rss/search?p=%22how+to+cook+bacon%22&scope=all&fltr= 的 Feed 中选择 * _en&question_status=all&date_subscribed=all&category=0&answer_count=any&orderby=rank'

您应该得到结果如下第一个结果,似乎与 UI 中显示的顺序匹配:

<item>
  <title>Resolved Question: How to cook bacon?
  <link>http://answers.yahoo.com/question/index?qid=20070416221341AAkZArM
  <guid isPermaLink="true">http://answers.yahoo.com/question/index?qid=20070416221341AAkZArM
  <pubDate>Tue, 17 Apr 2007 5:13:41 GMT
  <description>
</item>

在这些 RSS 结果中,数据量只是一个摘要,但您可以提取问题 id,然后使用 获取问题 API 方法 用于获取每个问题的所有详细信息。

I think Josh's answer was on the right track to the original issue of quoting or escaping the Answers query as it passes through YQL. But, playing with this further, I think the real problem is trying to duplicate the Answers UI results through the Answers API (which in turn is read by YQL).

I am not able to match the same set of results from the Answers API compared to the Answers website. I think the difference is the rank sort order, but that doesn't seem to be available in the API.

As an alternative, you could use the Answers RSS feeds and process them through YQL:

  1. Go to answers.yahoo.com and enter your sample search "how to cook bacon".
  2. On the results page, grab the RSS link on the left side nav (example)
  3. Use the RSS link along with the YQL "feed" module: select * from feed where url='http://answers.yahoo.com/rss/search?p=%22how+to+cook+bacon%22&scope=all&fltr=_en&question_status=all&date_submitted=all&category=0&answer_count=any&orderby=rank'

You should get results like the following first result, which seem to match the order shown in the UI:

<item>
  <title>Resolved Question: How to cook bacon?
  <link>http://answers.yahoo.com/question/index?qid=20070416221341AAkZArM
  <guid isPermaLink="true">http://answers.yahoo.com/question/index?qid=20070416221341AAkZArM
  <pubDate>Tue, 17 Apr 2007 5:13:41 GMT
  <description>
</item>

In these RSS results the amount of data is just a summary, but you could extract the question id, then use the get question API method to pull down all the details for each question.

笙痞 2025-01-03 23:14:50

您可以在 YQL 查询中使用单引号,然后在内容中添加双引号,YQL 会将双引号与数据一起传递到答案。像这样:

select * from answers.search where query='"how to cook bacon"' and type='resolved'

产生以下请求 答案

You can use single quotes for your YQL query and then put double quotes within your content and YQL will pass along the double quotes with the data to Answers. Like so:

select * from answers.search where query='"how to cook bacon"' and type='resolved'

yields the following request to Answers.

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