通过R或python中的google api进行google搜索 [英] google search by google api in r or python

查看:95
本文介绍了通过R或python中的google api进行google搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过python或R在Google中搜索某些内容(例如:"python语言"),它将为我提供该Google搜索的链接列表 像:

I want to search some thing (ex:"python language") in google by python or R and it will give me the list of links for that google search like:

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

是否有任何API 我经历了这个问题 如何获取Google搜索结果

Is there any api for that I went through this question How to get google search results

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

but problem is sometime it is working and most of the time it is not working and giving only empty list() as an output. thanks.

推荐答案

公开:我在SerpApi工作.

您可以使用 google-search-results 包从Google Maps获取数据. 在Repl.it上查看演示.

from serpapi.google_search_results import GoogleSearchResults

params = {
    "engine": "google",
    "q": "coffee"
}

client = GoogleSearchResults(params)
data = client.get_dict()

print("Organic results\n")

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"
          ]
        }
      }
    },
    {
      "position": 3,
      "title": "coffee - Amazon.com",
      "link": "https://www.amazon.com/coffee/s?k=coffee",
      "displayed_link": "www.amazon.com › coffee › k=coffee",
      "thumbnail": null,
      "snippet": "Amazon.com: coffee.",
      "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:wfQ5Et9Ni-kJ:https://www.amazon.com/coffee/s%3Fk%3Dcoffee+&cd=6&hl=en&ct=clnk&gl=us"
    },
    {
      "position": 4,
      "title": "What is Coffee? - National Coffee Association",
      "link": "http://www.ncausa.org/about-coffee/what-is-coffee",
      "displayed_link": "www.ncausa.org › About Coffee › What is Coffee?",
      "thumbnail": null,
      "snippet": "Everyone recognizes a roasted coffee bean, but you might not recognize an actual coffee plant. White flowers on coffee tree. Coffee trees are pruned short to ...",
      "cached_page_link": "http://webcache.googleusercontent.com/search?q=cache:eukMDyc_TlwJ:www.ncausa.org/about-coffee/what-is-coffee+&cd=15&hl=en&ct=clnk&gl=us"
    },
    {
      "position": 5,
      "title": "House of Coffi - Order Food Online - 107 Photos & 58 Reviews ...",
      "link": "https://m.yelp.com/biz/house-of-coffi-dover",
      "displayed_link": "m.yelp.com › Food › Coffee & Tea",
      "thumbnail": null,
      "snippet": "The coffee is good and the service is friendly. And I love the turkey/apple/Brie sandwich. Hooooowever I ordered one this morning and when… Read More.",
      "rich_snippet": {
        "top": {
          "detected_extensions": {
            "rating": 4.5,
            "reviews": 58,
            "price": 10,
            "price_range_under": 10
          },
          "extensions": [
            "Rating: 4.5",
            "58 reviews",
            "Price range: Under $10"
          ]
        }
      }
    },
    {
      "position": 6,
      "title": "THE BEST 10 Coffee & Tea in Dover, DE - Last Updated ...",
      "link": "https://www.yelp.com/search?cflt=coffee&find_loc=Dover%2C+DE",
      "displayed_link": "www.yelp.com › Dover, DE › Food",
      "thumbnail": null,
      "snippet": "Best Coffee & Tea in Dover, DE - House of Coffi, The Cobblestone Cafe, Governor's Cafe, Mugs Coffee Bar, La Baguette, Bavarian Bakery & Deli, Tim Hortons, ..."
    },
    {
      "position": 7,
      "title": "Coffee: Benefits, nutrition, and risks - Medical News Today",
      "link": "https://www.medicalnewstoday.com/articles/270202",
      "displayed_link": "www.medicalnewstoday.com › articles",
      "thumbnail": null,
      "snippet": "Drinking coffee can do much more than provide an energy boost. Some scientific studies have suggested that coffee can also reduce the risk of several health ...",
      "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:kzmdGVh8xu0J:https://www.medicalnewstoday.com/articles/270202+&cd=28&hl=en&ct=clnk&gl=us"
    },
    {
      "position": 8,
      "title": "Home | The Coffee Bean & Tea Leaf",
      "link": "https://www.coffeebean.com/",
      "displayed_link": "www.coffeebean.com",
      "thumbnail": null,
      "snippet": "Learn More. Free Delivery The Coffee Bean & Tea Leaf Food and Beverages ... Rewards. Order Ahead and Mobile Pay using The Coffee Bean® Rewards app.",
      "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:WpQxSYo2c6AJ:https://www.coffeebean.com/+&cd=29&hl=en&ct=clnk&gl=us",
      "related_pages_link": "https://www.google.com/search?hl=en&gl=us&q=related:https://www.coffeebean.com/+Coffee&tbo=1&sa=X&ved=2ahUKEwjl7er0gLvoAhWRQN4KHRqmAQwQHzAcegQICRAF"
    },
    {
      "position": 9,
      "title": "Coffee beans | Peet's Coffee",
      "link": "https://www.peets.com/coffee",
      "displayed_link": "www.peets.com › coffee",
      "thumbnail": null,
      "snippet": "We start by sourcing the highest quality beans from farms around the world. Then we roast by hand to bring out the nuances in every cup, and deliver our coffee ...",
      "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:M0kq3m8QPKYJ:https://www.peets.com/coffee+&cd=30&hl=en&ct=clnk&gl=us"
    }
  ]
}

输出

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文档.

If you want more information, check out SerpApi documentation.

这篇关于通过R或python中的google api进行google搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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