<jupyter_start><jupyter_text>Notebook for programmatic use of Google Search  1. Setup  Mount Google DriveSo that we have somewhere (permanent) to save results if needed.<jupyter_code>from google.colab import drive
drive.mount('/content/drive')
import requests   # library to access web content - https://docs.python-requests.org/en/latest/
from bs4 import BeautifulSoup   # https://www.crummy.com/software/BeautifulSoup/bs4/doc/<jupyter_output><empty_output><jupyter_text>2. Using the Google Search API<jupyter_code>from googlesearch import search

# Docs: https://python-googlesearch.readthedocs.io/en/latest/
query = "penfolds 2017 max chardonnay"
def get_google_search_result(query, language="en", n_result=15):
  print("query: " + query)
  return [result for result in search(
      query,             # The query you want to run
      tld="com",         # The top level domain
      lang=language,     # The language e.g. english
      num=20,            # Number of results per page
      start=0,           # First result to retrieve
      stop=n_result,     # Last result to retrieve
      pause=2.0,         # Lapse between HTTP (web) requests
      )]
results_list = get_google_search_result(query)
results_list           # display results
results_list[0]
r = requests.get(results_list[0])
r
r.text<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09417040358744394, 'fraction_numerical': 0.012705530642750373, 'mean_word_length': 3.508417508417508, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '394452', 'license': 'Apache-2.0', 'n_tokens_mistral': 423, 'n_tokens_neox': 410, 'n_words': 115, 'path': 'notebooks/GoogleSeach_Notebook.ipynb', 'repo_name': 'emmegb/personal-wine-catalogue', 'size': '1338'}