Extraer Encabezados usando BeautifulSoup

Python es un lenguaje de programación que es catalogado como fácil cuando le comparamos con otros alternativas como Javascript, GoLang, etc.

Python tiene sus usos dentro del posicionamiento web, este puede ser usado para extraer datos de sitios que podemos usar para mejorar la estrategia.

Python cuenta con librerías que ayudan a extender lo que podemos hacer con este lenguaje de programación.

Una de esas librerías es BeautifulSoup.

Beautiful Soup es una librería que facilita la extracción de información de páginas web.

Extraer Encabezados Usando BeautifulSoup

import requests
from bs4 import BeautifulSoup

url = input("Enter the URL of the web page: ")

# Make a request to the URL
response = requests.get(url)

# Parse the HTML content of the page using BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')

# Find all the <h2> elements on the page
h2_headings = soup.find_all('h2')

# Check if there are any <h2> elements on the page
if h2_headings:
    print("H2 Headings found:")
    for heading in h2_headings:
        print(heading.text)
else:
    print("No H2 Headings found")
Categories SEO

Sobre Jose Manuel

Soy Manuel Campos, Profesor de Inglés, administrador de sitios web y creyente en aprender y compartir información sobre tecnología