In this post ,you ‘ll learn how to get company official website URL from company name in python. It is very much helpful to know regarding a company official website URL. This post is very helpful to the people who want to code regarding this topic. As well as the code provided below is also very much easier and it is also in a understandable method.
Get company official website URL from company name in Python
To get the company website URL which is official you need to import requests and Beautiful Soup (bs4) i .e you need to have them in your systems .You can follow the steps which are given below to get the URL of a company.
1)Import requests library.
import requests
2)Import beautiful Soup for parsing the HTML content.
from bs4 import Beautiful Soup
3)Construct the google search URL with the company name .
4)Loop through all the links .
5)If the website is found returns the link of website URL, otherwise returns ‘ none’.
6) Check the company name ,if website is found it will print the URL otherwise no URL will be seen there.
7)When you got the output URL you can simply copy it and paste in google ,directly it will lead you to company official website.
Now you can follow the below given code to get the company official website URL from company name in python.
#Import requests library import requests # Import BeautifulSoup for parsing HTML content from bs4 import BeautifulSoup def get_company_website(company_name): # Construct the Google search URL with the company name and "website" keyword search_url = f"https://www.google.com/search?q={company_name} website" response = requests.get(search_url) soup = BeautifulSoup(response.content, 'html.parser') #Loop through all links for result in soup.find_all('a'): if "website" in result.text.lower() and not result.has_attr('data-href'): # return the link's URL return result['href'] # If no website found, return None return None # Set the company name to search for company_name = "INFOSYS" website = get_company_website(company_name) # Check if a website was found if website: print(f"Website for {company_name}: {website}") else: print(f"Couldn't find a website for {company_name}")
OUTPUT:
Website for INFOSYS: /search?sca_esv=98d43e591c93d847&sca_upv=1&ie=UTF-8&q=Infosys+website+login&sa=X&ved=2ahUKEwipp47Al8mIAxXMSGwGHaabElwQ1QJ6BAgAEAI