Today we will create a website html tag finder with python it is like a web scraper with python. well this program will find and give you the tags of a website you can find the h1, a and other html tags of a page.
If you have a blog and you got some errors like multiple h1 in your page you can for multiple h1 in a page it is not recommended to have multiple h1 in a page because it effects seo.
This is very simple and easy project we will use some python libraries to make this project so without wasting much time let’s start.
If you are intrested in more coding projects than you check out our coderzway projects.
Making a website html tag finder with python
So first inorder to make a website html tag finder with python you need to have python installed on your machine I know you must have python installed.
If you don’t have python installed you can install it from the python website here – Download Python. Remember to click add python to path while installing.
So now you have python installed let’s create html tag finder
Create a .py file
Go to any folder and create a python file with .py extension and open it with a code editor. I am using vs code you can use anything I will recommend you to use vs code it has lot of advantages you can download vs code from here – Download vs code.
Install bs4 and requests
I have said that we will be using some python libraries so we need to install them the libraries are
requests – requests is python library with this you can make requests to any website and you can get the data. So you need to install this library you can install it with this command paste this in your command prompt
pip install requests
bs4 – Beautifulsoup is python library which is popurely used for web scraping this is web scraping only. So you need to install this library you can install it with this command paste this in your command prompt
pip install bs4
Copy and paste
Now you have installed everything final step is to copy and paste this code in your python file
# FIRST YOU NEED TO INSTALL REQUESTS AND BS4 # pip install bs4 # pip install requests # MADE BY CODERZWAY import requests as rq from bs4 import BeautifulSoup # ASKS THE USER FOR WEBSITE URL TO CHECK url = input('Enter the full url of a website to check : ') # ASKS THE USER FOR THE TAG THEY WANT TO FIND tag = input('Enter a tag to search : ') res = rq.get(url) htmlCon = res.content soup = BeautifulSoup(htmlCon,'html.parser') data = soup.find_all(tag) for i in data: print(i) print('')
After this you can run this file by opening command prompt or terminal at the file location and type this in the command prompt python filename.py This will run the file
How to use
1 – Enter the url of the website you want find the tags
2 – Enter the tag you want to find like h1, h2 or a
3 – You will get the list of tags.
So this was the website html tag finder with python you can add more features to this you can check out bs4 documentation.
Thank you for reading I hope you have found what you were looking for if you want more projects like this than subscribe to our newsletter.