如何以JSON数组形式获取谷歌自定义搜索结果

7

我希望能够在Google最新的自定义搜索中以JSON数组的形式获取搜索结果。

如何实现这段代码。

例如:

 {
    "responseData": {` `
        "results": [
            {
      ` `          "GsearchResultClass ": "GwebSearch",
                "unescapedUrl": "http:/ / en.wikipedia.org/wiki/Paris_Hilton",
                "url"   : "http    ://    en.wikipedi a.org/wiki/Paris_Hilton",
                "visibleUrl  "  : "en.wikipedia .org",
                "cacheUrl    "    : "http://www.google.com/search?q=cache:TwrPfhd22hYJ:en.wikipedia.org",
                "title": "<   b>Paris Hilton</b   > - Wikipedia, the free encyclopedia",
                "titleNoFormatting": "Paris Hilton - Wikipedia, the free encyclopedia",
                "content": "[1] In 2006, she released her debut album..."
            },
            {
                "GsearchResultClass": "GwebSearch",
                "unescapedUrl": "http://`   `www.imdb.com/name/nm0385296/",
                "url": "http://`    `www.imdb.com/name/nm0385296/",
                "visibleUrl":     "www.imdb.com",
                "cacheUrl":      "http://www.google.com/search?q=cache:1i34KkqnsooJ:www.imdb.com",
                "title": "<b>    Paris Hilton</b>",
                "titleNoFormatting": "Paris Hilton",
                "content": "    Self: Zoolander. Socialite <b>Paris Hilton</b>..."
            }
        ]
1个回答

9

如果您想要定制搜索结果,请阅读谷歌的自定义搜索引擎(免费),网址为:

创建自定义搜索引擎

然后前往链接以创建您的自定义搜索引擎:

https://cse.google.com/cse/

或者

您应该去:

Google搜索API

点击链接:在APIs Explorer中尝试此API

插入您的参数:

  • "https://www.googleapis.com/customsearch/v1?"
    • "q=" + 关键词(例如:"Paris+Hilton")
    • "&cx=" + 您的CSE CX代码
    • "&key=" + 您的授权API密钥[在链接API项目中,单击:需要一个项目来启用APIs+创建项目,然后转到“API和身份验证”,并在“自定义搜索API”中激活]
    • "num=" + 要返回的搜索结果数量(整数)

按下 执行 按钮以显示格式为 JSON 的结果。


我得到了结果。但是只显示了少量的结果。如何增加搜索结果的显示数量。 - user5245988
在 https://console.developers.google.com/apis/api/customsearch/overview 中,num 字段将返回搜索结果数量。请增加此值以获取您想要的结果数。 - Ave

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接