如何使用 Yahoo 的 Answer API 对 YQL 中的字符进行转义?
我通过 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 Josh 的答案对于在通过 YQL 时引用或转义答案查询的原始问题是正确的。但是,进一步研究这个问题,我认为真正的问题是尝试通过 Answers API 复制 Answers UI 结果(反过来由 YQL 读取)。
与问答网站。我认为区别在于排序顺序,但这似乎在 API 中不可用。
作为替代方案,您可以使用 Answers RSS 源并通过 YQL 处理它们:
从 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 中显示的顺序匹配:
在这些 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:
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:
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.
您可以在 YQL 查询中使用单引号,然后在内容中添加双引号,YQL 会将双引号与数据一起传递到答案。像这样:
产生以下请求 答案。
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:
yields the following request to Answers.