【问题标题】:Google Search API - getting "regular" Google resultGoogle Search API - 获取“常规”Google 结果
【发布时间】:2013-05-06 19:29:10
【问题描述】:

我想做一些谷歌搜索并获得与在 www.google.se 上搜索相同的结果(我在瑞典)。我创建了一个 Google API 帐户来获取 API 密钥,https://code.google.com/apis/console/b/0/。

我这样调用 API:

https://www.googleapis.com/customsearch/v1?key=KEY&cx=013036536707430787589:_pqjad5hr1a&gl=se&cr=se&googlehost=google.se&q=bästa espressomaskin&alt=json

但是,这与我通常会在“bästa espressomaskin”上搜索得到的结果不同,我不知道为什么。

我的第二个问题是关于参数“cx”。它实际上是什么,它有什么作用?我只是使用了 Google API 介绍网站上提供的那个。

我还想要超过 10 个结果,我的 API 控制台帐户上有一些钱,但是我如何才能将我的“num”参数设置为超过 10?

谢谢

【问题讨论】:

  • 我希望通过网络浏览器执行的搜索结果将包括个人/个性化结果;但通过 API 的搜索查询不会。

标签: rest google-custom-search


【解决方案1】:

cx 是您注册其自定义搜索服务时获得的 Google 密钥。它允许您自定义搜索。更多信息请看这里:https://developers.google.com/custom-search/v1/getting_started

至于结果,Google 在他们的文档中表示您的结果可能会有所不同。更多信息请看这里:http://support.google.com/customsearch/bin/answer.py?hl=en&answer=2633385

【讨论】:

    【解决方案2】:

    您可以使用 SerpApi 访问从常规 Google 搜索结果中提取的数据。

    与curl 一起使用的示例。

    curl -s 'https://serpapi.com/search?q=coffee&location=Sweden&google_domain=google.se&gl=se&hl=sv&num=100'
    

    这是通过google-search-results 包使用它的示例。

    from serpapi import GoogleSearch
    import os
    
    params = {
        "engine": "google",
        "q": "coffee",
        # "q": "bästa espressomaskin",
        "location": "Sweden",
        "google_domain": "google.se",
        "gl": "se",
        "hl": "sv",
        "num": 100,
        "api_key": os.getenv("API_KEY")
    }
    
    client = GoogleSearch(params)
    data = client.get_dict()
    
    print("Organic results")
    
    for result in data['organic_results']:
        print(f"""
    Title: {result['title']}
    Link: {result['link']}
    Position: {result['position']}
    Snippet: {result['snippet']}
    """)
    

    检查SerpApi playground 或documentation 中的其他提取数据。

    免责声明:我在 SerpApi 工作。

    【讨论】:

      猜你喜欢
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多