Get Company official website URL from company name in Python

Here we are going to write a code in python where we can get company official website URL  by just entering the company name. We can be easily reach to company website using the company name.

These code will be very easy and simple to understand.

Algorithm

  • At first we are going to import the module.
  • Then we are going to enter the name of the company.
  • We are going to use the try block and request the URL.
  • Then we will use the for loop and if condition to print the company website URL.
  • Break the loop. By default company name is invalid it will not show the  official company website URL.

Source Code

To Get Company official website URL from company name.

import requests
from bs4 import BeautifulSoup


company_name=input("enter the name of company  to search : ").lower()
company_url=f"https://www.google.com/search?q={company_name}"


try:
  response=requests.get(company_url)
  response.raise_for_status()
  soup=BeautifulSoup(response.content,"html.parser")
  for link in soup.find_all("a"):
    if company_name.lower() in link.get("href",'').lower():
      website_url=link.get("href")
      print(f"the official website for {company_name} is https://www.{company_name}.com{website_url}")
      break
except requests.exceptions.RequestException as e:
  print(f"An error occurred: {e}")
  print(f"could not find the the official website for {company_name}")

Output:

https://www.google.com/search?q=google&sca_esv=72aaa3890415b76e&sca_upv=1&ie=UTF-8&gbv=1&sei=8XvpZtmRD_WcseMPnZjq2AU

 

Leave a Comment

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

Scroll to Top