是否有适用于 Google 答案框的 API? [英] Is there an API for the Google Answer Boxes?

查看:26
本文介绍了是否有适用于 Google 答案框的 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 答案框(有时称为精选摘要、知识卡或实时结果)非常有用.我想提取信息并在我自己的程序中使用它.看看 HTML 代码,它不像从那里拉出来那么直接.我做了很多研究,但似乎找不到任何支持它们的方法.有谁知道是否有 API(或 Web Search API 的一部分)可以让您检索从应答框返回的信息?

我在这里看到了答案:

举个例子,这是日本现在几点了"的 HTML 代码:

<div class="vk_c vk_gy vk_sh card-section _MZc"><div class="vk_bk vk_ans">6:37 AM</div><div class="vk_gy vk_sh">星期二,<span class="_Hq">2015 年 8 月 4 日</span><span class="_Hq">(GMT+9) </span>

<span class="vk_gy vk_sh">日本时间 </span>

这与东京在哪里"有很大不同:

<div class="_uX kno-fb-ctx" aria-level="3" role="heading" data-hveid="41" data-ved="0CCkQtwcoATACahUKEwiLjemg8I3HAhUTKYgKHU7jCho"><div class="_eF" data-tts="answers" data-tts-text="Japan">日本</div><div class="_Tfc"></div></div><!--n--></li><li class="mod" data-md="61" style="clear:none"><!--m--><div class="_oDd" data-hveid="42"><span class="_Tgc _y9e">东京由关东地区的西南部、<b>伊豆群岛</b>和<b>小笠原群岛</b>组成.东京是<b>日本</b>的首都,也是超过 1300 万人居住的地方,是世界上人口最多的城市之一.</span></div>

我基本上需要从第一个中提取6:37 AM",从第二个中提取Japan",但是执行动态字符串搜索会很困难,因为它们的格式非常不同.

解决方案

DuckDuckGo 提供了一个即时答案 api,我过去使用过它,效果很好.反应不如谷歌那么有力,但这是一个好的开始.

https://duckduckgo.com/api

API 在 JSON 响应中看起来像这样.

<代码>{抽象的: ""摘要文本:"摘要来源:""摘要网址:"图片: ""标题:"回答: ""重定向:"答案类型:"定义: ""定义来源:"定义网址:"相关话题: [ ]结果: [ ]类型: ""}

我希望这会有所帮助!

The Google Answer Boxes (sometimes called Featured Snippets, Knowledge Cards, or Live Results) are extremely helpful. I'd like to extract the information and use it in my own program. Looking at the HTML code, it's not quite so straight forward as pulling it from there. I've done quite a bit of research, but I can't seem to find any support for them. Does anyone know if there is an API (or part of the Web Search API) where you can retrieve the information returned from the Answer Box?

I saw the answer here: google api for glorious info box? , but the solution presented was deprecated last month.

Just for an example, this is the HTML code for "What is the time in japan":

<!--m--><div data-hveid="30">      
<div class="vk_c vk_gy vk_sh card-section _MZc">  
<div class="vk_bk vk_ans">6:37 AM</div> 
<div class="vk_gy vk_sh"> Tuesday, <span class="_Hq">August 4, 2015</span>  
<span class="_Hq"> (GMT+9) </span>  
</div> <span class="vk_gy vk_sh">  Time in Japan  </span> 

Which is VERY different from "where is tokyo located":

<!--m-->
<div class="_uX kno-fb-ctx" aria-level="3" role="heading" data-hveid="41" data-ved="0CCkQtwcoATACahUKEwiLjemg8I3HAhUTKYgKHU7jCho">
<div class="_eF" data-tts="answers" data-tts-text="Japan">Japan</div>
<div class="_Tfc">
</div></div>
<!--n-->
</li><li class="mod" data-md="61" style="clear:none">
<!--m-->
<div class="_oDd" data-hveid="42">
<span class="_Tgc _y9e">Tokyo consists of the southwestern part of the Kanto region, the <b>Izu Islands</b>, and the <b>Ogasawara Islands</b>. Tokyo is the capital of <b>Japan</b>, and the place where over 13 million people live, making it one of the most populous cities in the world.</span></div>

I essentially need to extract "6:37 AM" from the first and "Japan" from the second, but performing a dynamic string search would be difficult as they are in very different formats.

解决方案

There is an instant answer api available from DuckDuckGo that I've used in the past that works pretty well. The responses aren't as robust as google's but it's a good start.

https://duckduckgo.com/api

The api looks like so in a JSON response.

{
Abstract: ""
AbstractText: ""
AbstractSource: ""
AbstractURL: ""
Image: ""
Heading: ""
Answer: ""
Redirect: ""
AnswerType: ""
Definition: ""
DefinitionSource: ""
DefinitionURL: ""
RelatedTopics: [ ]
Results: [ ]
Type: ""
}

I hope this helps!

这篇关于是否有适用于 Google 答案框的 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆