in this article you are going to learn about, how to get company official website URL by company name using python. As the technology grows day by day it is very easy for hackers to clone the websites. Hence they can create Phishing websites to steal your information and passwords etc. so it hard to find the official websites. This python code will be useful to go to the official website by the company name
TO GET URL OF COMPANY WEBSITE WITH PYTHON:
To get the URL of company with python first you need a python package called BEAUTIFUL SOUP. This package will help you to get the official URL of a company using python. This package is used for WEB SCRAPING. The beautiful soup is one of the best option to get the URL’s
BEAUTIFUL SOUP :
It is a Python library aimed at helping programmers who are trying to scrape data from websites. To install this package use this command: pip install beautifulsoup4. It can get any information from webpages.
Requests:
Requests module allows you to send HTTP requests very easily. The HTTP request returns a Response objects. you can install it by typing pip install requests
PYTHON CODE TO GET URL OF COMPANY WEBSITE :
First we need to install basic packages:
pip install beautifulsoup4
python code:
import requests #importing packages from bs4 import BeautifulSoup # importing beautiful soup company_name=input("enter the name to search : ").lower() # to get name of the company and converting it into lowercase you can give any company name here search_url=f"https://www.google.com/search?q={company_name}" #giving the search url try: # exception handeling response=requests.get(search_url) # here we try to get the search the search_url and catch the HTTP errors response.raise_for_status() # to rise an exception for HTTP errors soup=BeautifulSoup(response.content,"html.parser") # here response.content is object containing the HTML content for link in soup.find_all("a"): if company_name.lower() in link.get("href",'').lower(): #if we get the company name then we store it in the website_url variable website_url=link.get("href") print(f"the official website for {company_name} is https://www.google.com{website_url}") # printing the company URL if you want to go directly into their webpage just replace here google with{company_name} and you will directly go to their webpage break except requests.exceptions.RequestException as e: #handeling exceptions print(f"An error occurred: {e}") print(f"could not find the the official website for {company_name}")
Output:
enter the name to search : amazon the official website for amazon is
using this code you can get the website URL with the help of python. Hope this will help you.
this code will simply take the name of the company and process it then it will give the output that is the link of the company. You can paste it in the google or just click on it to go to that website. If there are any errors it will print that there is some error or webpage not found. this is a simple method, but there are also some more efficient methods.