To Get official website URL from company name in Python

This guide demonstrates two efficient methods to retrieve a company’s official website using Python. The first method utilizes the Clearbit Company API, offering quick and reliable access to company data with minimal setup. The second method leverages Google’s Custom Search JSON API, providing more flexibility for search-based queries. Both approaches include step-by-step instructions, code examples, and details on setting up API credentials. Ideal for developers looking to integrate company data into their applications without relying on web scraping.

Get official website URL from company name in Python

Method 1: Using Clearbit API (Simple and Reliable)

Clearbit provides a free API (with limitations) to get company data, including the official website.

Step 1: Install Requests

pip install requests

Step 2: Python Code with Clearbit API

import requests

def get_official_website(company_name):
    # Replace with your Clearbit API key
    api_key = 'YOUR_CLEARBIT_API_KEY'
    headers = {'Authorization': f'Bearer {api_key}'}

    # Clearbit API endpoint
    url = f"https://company.clearbit.com/v2/companies/find?name={company_name}"
    
    response = requests.get(url, headers=headers)
    
    if response.status_code == 200:
        data = response.json()
        return data.get('domain', 'Website not found.')
    else:
        return "Company not found."

# Example usage
company_name = "Microsoft"
website = get_official_website(company_name)
print("Official Website:", website)

Method 2: Using Google Custom Search JSON API

If you prefer Google, use the Custom Search API:

Step 1: Set Up Google API

  1. Go to Google Cloud Console.
  2. Enable the Custom Search API.
  3. Create API credentials.
  4. Set up a Custom Search Engine (CSE) and get the cx code.

Step 2: Python Code with Google API

import requests

def get_official_website(company_name):
    api_key = "YOUR_GOOGLE_API_KEY"
    cse_id = "YOUR_CUSTOM_SEARCH_ENGINE_ID"
    
    url = f"https://www.googleapis.com/customsearch/v1?q={company_name}+official+website&key={api_key}&cx={cse_id}"
    
    response = requests.get(url)
    data = response.json()
    
    if "items" in data:
        return data["items"][0]["link"]
    else:
        return "Website not found."

# Example usage
company_name = "Apple"
website = get_official_website(company_name)
print("Official Website:", website)

Key Points:

  • Replace YOUR_GOOGLE_API_KEY and YOUR_CUSTOM_SEARCH_ENGINE_ID with actual values.
  • This method is reliable for accuracy but may incur API costs if used heavily.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top