import requests
link = "https://www.plus2net.com/html_tutorial/html_form.php"
content = requests.get(link)
from bs4 import BeautifulSoup
soup = BeautifulSoup(content.text, 'html.parser')
print(soup.find_all("h2"))
Output is here
[<h2>How to select a form component</h2>,
<h2>Form tag</h2>, <h2>Method attribute of the html form</h2>,
<h2>Action attribute</h2>,
<h2>Applications and uses of html form elements</h2>]
If you don't want to keep the <h2> </h2>tags, then use this
my_list=soup.find_all("h2")
for my_tags in my_list:
print(my_tags.string)
import requests
link = "https://www.plus2net.com/html_tutorial/html_form.php"
content = requests.get(link)
from bs4 import BeautifulSoup
soup = BeautifulSoup(content.text, 'html.parser')
print(soup.find_all('a')) # all the links with string and tags
The output will be all the links present in the webpage.
my_list=soup.find_all("a")
for my_tags in my_list:
#print(my_tags['href']) # returns the links or URLs
print(my_tags.string) # returns the string or anchored string
import requests
link = "https://www.plus2net.com/html_tutorial/html_form.php"
content = requests.get(link)
from bs4 import BeautifulSoup
soup = BeautifulSoup(content.text, 'html.parser')
import re
print(soup.find_all(re.compile("(h[1|2])")))
We will get one list as output
[<h1 itemprop="headline">Web Form tag & HTML elements</h1>,
<h2>How to select a form component</h2>, <h2>Form tag</h2>,
<h2>Method attribute of the html form</h2>,
<h2>Action attribute</h2>,
<h2>Applications and uses of html form elements</h2>]
all a or div tags
import re
#print(soup.find_all(re.compile("(a|div)"))) # all a or div tags
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.