Scrape Google News results using SerpApi

PHOTO EMBED

Mon May 03 2021 14:16:22 GMT+0000 (UTC)

Saved by @ilyazub #webscraping #googlenews #serpapi

import os

# https://github.com/serpapi/google-search-results-python
from serpapi import GoogleSearch

params = {
  "engine": "google",
  "q": "cute animals",
  "tbm": "nws",
  "api_key": os.getenv("API_KEY"),
}

search = GoogleSearch(params)

pages = search.pagination()

for result in pages:
  print(f"Current page: {result['serpapi_pagination']['current']}")

  for news_result in result["news_results"]:
      print(f"Title: {news_result['title']}\nLink: {news_result['link']}\n")
content_copyCOPY

https://replit.com/@DimitryZub1/Scrape-Google-News-with-Pagination-python-serpapi