Get company website URL from company name in python

In this tutorial, we will learn how to get a company website URL from a company name with some easy-to-understand code in Python. This code is much easier to understand than it sounds.
If you don’t know how to write Python code to get a valid URL just from a company’s name then you are at the right place to learn that using just a few lines of code.

Step 1: Open the terminal and install the required package
pip install googlesearch-python
  • This line imports the ‘search’ function from ‘googlesearch-python’  library.
  • The ‘search’ function will allow you to search the company’s name directly from the Python script.

 

Step 2:Write the following  code
from googlesearch import search

def get_website(company_name):
 query = f"{company_name} official website"
 for url in search(query, num_results=1):
  return url

company_name = "CodeSpeedy"
website_url = get_website(company_name)

print(f"Website URL for this company's name is {company_name}:{website_url}")
  • ‘search(query,num_results=1)’  performs a Google search and returns the first result.

Output:

When you run the code, you will get the URL of the company’s official website.

for example
Website URL for this company's name is CodeSpeedy:https://www.codespeedy.com/

for more details visit:

http://www.codespeedy.com

 

 

 

 

Leave a Comment

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

Scroll to Top