Disclaimer: I work at SerpApi.
You can use the google-search-results
package to extract links from Google Search.
Full example at Repl.it
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 results\n")
for result in data['organic_results']:
print(f"Link: {result['link']}")
Response
{
"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...
]
}
Output
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/
If you want more information, check out SerpApi documentation.