谷歌的“定义:"通过 API? [英] Google's "define: " through an API?

查看:24
本文介绍了谷歌的“定义:"通过 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得在 Google 中使用特殊功能的搜索结果,例如define: [phrase]",但我似乎找不到相关信息.

I want to get the result of searches that use special features in Google, like "define: [phrase]" and I can't seem to find relevant information about this.

有谁知道我可以在哪里获取 JSON 格式的数据(如 Google 的其他 API),而无需手动抓取结果页面?

Does anyone knows where I can get the data in JSON format (like the rest of Google's APIs) without scraping the results page manually?

谢谢,以利

推荐答案

我希望我没有为此设置赏金,因为几天后我偶然发现了答案,这真的很简单.

I wish I had not set a bounty for this, because I stumbled upon the answer a few days later and it is really simple.

如果您想要一个的定义,请访问以下网址:

Here is URL to call if you want a definition to love:

http://www.google.com/dictionary/json?callback=a&sl=en&tl=en&q=love

你会得到一个包含 JSONP 的响应流,内容如下(美化"用于学习,API 一行返回):

You will get a response stream containing JSONP, with the following contents ("prettified" for learning purposes, API returns all in one line):

a(
    {
       "query":"love",
       "sourceLanguage":"en",
       "targetLanguage":"en",
       "primaries":[
          {
             "type":"headword",
             "terms":[
                {
                   "type":"text",
                   "text":"love",
                   "language":"en",
                   "labels":[
                      {
                         "text":"Noun",
                         "title":"Part-of-speech"
                      }
                   ]
                },
                {
                   "type":"phonetic",
                   "text":"/ləv/",
                   "language":"und"
                },
                {
                   "type":"sound",
                   "text":"http://www.gstatic.com/dictionary/static/sounds/de/0/love.mp3",
                   "language":"und"
                }
             ],
             "entries":[
                {
                   "type":"related",
                   "terms":[
                      {
                         "type":"text",
                         "text":"loves",
                         "language":"und",
                         "labels":[
                            {
                               "text":"plural"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"An intense feeling of deep affection",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"babies fill parents with intense feelings of x3cemx3elovex3c/emx3e",
                               "language":"en"
                            }
                         ]
                      },
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"their x3cbx3ex3cemx3elovex3c/emx3e forx3c/bx3e their country",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"A deep romantic or sexual attachment to someone",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"it was x3cemx3elovex3c/emx3e at first sight",
                               "language":"en"
                            }
                         ]
                      },
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"they were both x3cbx3ein x3cemx3elovex3c/emx3e withx3c/bx3e her",
                               "language":"en"
                            }
                         ]
                      },
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"we were slowly x3cbx3efalling in x3cemx3elovex3c/emx3ex3c/bx3e",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"A personified figure of x3cemx3elovex3c/emx3e, often represented as Cupid",
                         "language":"en"
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"A great interest and pleasure in something",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"his x3cbx3ex3cemx3elovex3c/emx3e forx3c/bx3e football",
                               "language":"en"
                            }
                         ]
                      },
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"we share a x3cbx3ex3cemx3elovex3c/emx3e ofx3c/bx3e music",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"Affectionate greetings conveyed to someone on onex27s behalf",
                         "language":"en"
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"A formula for ending an affectionate letter",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"take care, lots of x3cemx3elovex3c/emx3e, Judy",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"A person or thing that one x3cemx3elovesx3c/emx3e",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"she was x3cbx3ethe x3cemx3elovex3c/emx3e of his lifex3c/bx3e",
                               "language":"en"
                            }
                         ]
                      },
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"their two great x3cemx3elovesx3c/emx3e are tobacco and whiskey",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"A friendly form of address",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"itx27s all right, x3cemx3elovex3c/emx3e",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"Used to express affectionate approval for someone",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"donx27t fret, therex27s a x3cemx3elovex3c/emx3e",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"(in tennis, squash, and some other sports) A score of zero; nil",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"x3cemx3elovex3c/emx3e fifteen",
                               "language":"en"
                            }
                         ]
                      },
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"he was down two sets to x3cemx3elovex3c/emx3e",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                }
             ]
          },
          {
             "type":"headword",
             "terms":[
                {
                   "type":"text",
                   "text":"love",
                   "language":"en",
                   "labels":[
                      {
                         "text":"Verb",
                         "title":"Part-of-speech"
                      }
                   ]
                },
                {
                   "type":"phonetic",
                   "text":"/ləv/",
                   "language":"und"
                },
                {
                   "type":"sound",
                   "text":"http://www.gstatic.com/dictionary/static/sounds/de/0/love.mp3",
                   "language":"und"
                }
             ],
             "entries":[
                {
                   "type":"related",
                   "terms":[
                      {
                         "type":"text",
                         "text":"loved",
                         "language":"und",
                         "labels":[
                            {
                               "text":"past participle"
                            }
                         ]
                      },
                      {
                         "type":"text",
                         "text":"loves",
                         "language":"und",
                         "labels":[
                            {
                               "text":"3rd person singular present"
                            }
                         ]
                      },
                      {
                         "type":"text",
                         "text":"loving",
                         "language":"und",
                         "labels":[
                            {
                               "text":"present participle"
                            }
                         ]
                      },
                      {
                         "type":"text",
                         "text":"loved",
                         "language":"und",
                         "labels":[
                            {
                               "text":"past tense"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"Feel a deep romantic or sexual attachment to (someone)",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"do you x3cemx3elovex3c/emx3e me?",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                },
                {
                   "type":"meaning",
                   "terms":[
                      {
                         "type":"text",
                         "text":"Like very much; find pleasure in",
                         "language":"en"
                      }
                   ],
                   "entries":[
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"Ix27d x3cemx3elovex3c/emx3e a cup of tea, thanks",
                               "language":"en"
                            }
                         ]
                      },
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"I just x3cemx3elovex3c/emx3e dancing",
                               "language":"en"
                            }
                         ]
                      },
                      {
                         "type":"example",
                         "terms":[
                            {
                               "type":"text",
                               "text":"a fun-x3cemx3elovingx3c/emx3e girl",
                               "language":"en"
                            }
                         ]
                      }
                   ]
                }
             ]
          }
       ]
    }
,200,null)

Google Dictionary API 以回调函数 (JSONP) 的形式返回.在您可以在函数调用中处理 JSON 之前,您必须去除回调函数数据.

Google Dictionary API returns in the form of a callback function (JSONP). Before you can process the JSON within the function call, you have to strip out the callback function data.

这意味着删除第一个 { 之前的所有内容以及最后一个 } 之后的所有内容.

That means removing everything before the first { and everything after the last }.

在这之后你就完成了!这就是您需要的所有信息,当您在 Google 上搜索 define love 时,这些信息基本相同(实际上多一点!).

After this you are done! That's all information you need and it's basically the same (actually a little more!) information when you search Google for define love.

这篇关于谷歌的“定义:"通过 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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