谷歌搜索通过谷歌API在r或python



我想搜索一些东西(例如:"python语言")在谷歌通过python或R,它会给我链接的谷歌搜索列表如:

https://en.wikipedia.org/wiki/Python_(programming_language)
https://www.python.org/
https://www.python.org/about/gettingstarted/

有api吗我仔细研究了这个问题如何获得谷歌搜索结果

,但问题是有时它是工作的,大多数时候它不工作,只给出空list()作为输出。谢谢。

免责声明:我在SerpApi工作

您可以使用google-search-results包从Google搜索中提取链接。

完整示例:

import os
from serpapi import GoogleSearch
params = {
    "engine": "google",
    "q": "coffee",
    "api_key": os.getenv("API_KEY")
}
client = GoogleSearch(params)
data = client.get_dict()
print("Organic resultsn")
for result in data['organic_results']:
  print(f"Link: {result['link']}")
反应

{
    "organic_results": [
    {
      "position": 1,
      "title": "Coffee - Wikipedia",
      "link": "https://en.wikipedia.org/wiki/Coffee",
      "displayed_link": "en.wikipedia.org › wiki › Coffee",
      "thumbnail": null,
      "snippet": "Coffee is a brewed drink prepared from roasted coffee beans, the seeds of berries from certain Coffea species.",
      "sitelinks": {
        "inline": [
          {
            "title": "History of coffee",
            "link": "https://en.wikipedia.org/wiki/History_of_coffee"
          },
          {
            "title": "Coffee bean",
            "link": "https://en.wikipedia.org/wiki/Coffee_bean"
          },
          {
            "title": "Coffee production",
            "link": "https://en.wikipedia.org/wiki/Coffee_production"
          },
          {
            "title": "Coffee preparation",
            "link": "https://en.wikipedia.org/wiki/Coffee_preparation"
          }
        ],
        "list": [
          {
            "date": "Color‎: ‎Black, dark brown, light brown, beige"
          }
        ]
      },
      "rich_snippet": {
        "bottom": {
          "detected_extensions": {
            "introduced‎_‎th_century": 15
          },
          "extensions": [
            "Introduced‎: ‎15th century",
            "Color‎: ‎Black, dark brown, light brown, beige"
          ]
        }
      },
      "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:U6oJMnF-eeUJ:https://en.wikipedia.org/wiki/Coffee+&cd=4&hl=en&ct=clnk&gl=us",
      "related_pages_link": "https://www.google.com/search?hl=en&gl=us&q=related:https://en.wikipedia.org/wiki/Coffee+Coffee&tbo=1&sa=X&ved=2ahUKEwjl7er0gLvoAhWRQN4KHRqmAQwQHzADegQIAhAH"
    },
    {
      "position": 2,
      "title": "The House of Coffi - Coffee Shop - Dover, Delaware - 132 ...",
      "link": "https://www.facebook.com/TheHouseOfCoffi/",
      "displayed_link": "www.facebook.com › Places › Dover, Delaware › Restaurant",
      "thumbnail": null,
      "snippet": "People talk about "iced mocha coffee", "flavored iced tea" and "chai tea". Relaxing atmosphere・Expert baristas・Convenient location. My first visit was a very ...",
      "rich_snippet": {
        "top": {
          "detected_extensions": {
            "rating": 5,
            "votes": 132
          },
          "extensions": [
            "Rating: 5",
            "132 votes"
          ]
        }
      }
    }
    // Stripped...
  ]
}

Organic results
Link: https://en.wikipedia.org/wiki/Coffee
Link: https://www.amazon.com/coffee/s?k=coffee
Link: https://www.kansas.com/entertainment/restaurants/dining-with-denise-neil/article4383840.html
Link: https://www.reverieroasters.com/
Link: https://www.medicalnewstoday.com/articles/270202
Link: http://www.ncausa.org/about-coffee/what-is-coffee
Link: http://www.ncausa.org/about-coffee
Link: https://www.facebook.com/KookaburraCoffeeLyfe/

如果您想了解更多信息,请查看SerpApi文档

我已经使用这个python web搜索api在python中执行谷歌搜索。

相关内容

  • 没有找到相关文章

最新更新