Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

html - Is there an API for the Google Answer Boxes?

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.

enter image description here

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...