Import packages and credentials

# Packages
from serpapi import GoogleSearch
import pandas as pd
import numpy as np
NaN = np.nan

# Import credentials
# Import via the method you prefer


Import csv and creat a website column

# Read in csv of company names
df = pd.read_csv("my_company_name_list.csv")

# Make blank column for website links
df["website"] = NaN


Iterate through company names and update website column

# Iterate through companies
for count, value in enumerate(df["company_name"]):
    
    params = {
      "api_key": "your_api_token",
      "engine": "google",
      "q": value,
      "location": "United States",
      "google_domain": "google.com",
      "gl": "us",
      "hl": "en"
    }

    search = GoogleSearch(params)
    results = search.get_dict()
    
        
    try: results["organic_results"]
    except KeyError: results["organic_results"] = None
    
    if results["organic_results"] == None:
        
        df.loc[count, "website"] = "Manual Search"   
        
    else:        
        
        current_website = results["organic_results"][0]["link"]
    
        # Insert website into df
        df.loc[count, "website"] = current_website

   


Export csv

# csv export
df.to_csv("new_company_websites.csv",index=False)