Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Navegación del Documento HTML | Descifrando HTML con Beautiful Soup
Web Scraping con Python

bookNavegación del Documento HTML

Después de leer el documento HTML, tienes la flexibilidad de navegarlo de varias maneras. Para profundizar, puedes especificar una etiqueta igual que un atributo. Por ejemplo, examinemos el elemento <head> y representémoslo en una forma 'estructurada' (empleando el método .prettify()).

123456789101112
# Importing libraries from bs4 import BeautifulSoup from urllib.request import urlopen # Reading web page url = "https://codefinity-content-media.s3.eu-west-1.amazonaws.com/18a4e428-1a0f-44c2-a8ad-244cd9c7985e/jesus.html" page = urlopen(url) html = page.read().decode("utf-8") # Reading HTML with BeautifulSoup soup = BeautifulSoup(html, "html.parser") print(soup.head.prettify())
copy

Puedes experimentar sustituyendo el atributo .head por .body, por ejemplo. Como se muestra arriba, el elemento <head> abarca varios elementos secundarios. Puedes iterar a través de todos los hijos de los elementos utilizando un bucle for y el atributo .children.

1234567891011121314
# Importing libraries from bs4 import BeautifulSoup from urllib.request import urlopen # Reading web page url = "https://codefinity-content-media.s3.eu-west-1.amazonaws.com/18a4e428-1a0f-44c2-a8ad-244cd9c7985e/jesus.html" page = urlopen(url) html = page.read().decode("utf-8") # Reading HTML with BeautifulSoup soup = BeautifulSoup(html, "html.parser") # Iterating over all element children for child in soup.head.children: print(child)
copy

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you explain what the .prettify() method does?

How can I iterate over the children of the <body> element instead?

What other attributes or methods can I use to navigate the HTML structure?

Awesome!

Completion rate improved to 4.35

bookNavegación del Documento HTML

Desliza para mostrar el menú

Después de leer el documento HTML, tienes la flexibilidad de navegarlo de varias maneras. Para profundizar, puedes especificar una etiqueta igual que un atributo. Por ejemplo, examinemos el elemento <head> y representémoslo en una forma 'estructurada' (empleando el método .prettify()).

123456789101112
# Importing libraries from bs4 import BeautifulSoup from urllib.request import urlopen # Reading web page url = "https://codefinity-content-media.s3.eu-west-1.amazonaws.com/18a4e428-1a0f-44c2-a8ad-244cd9c7985e/jesus.html" page = urlopen(url) html = page.read().decode("utf-8") # Reading HTML with BeautifulSoup soup = BeautifulSoup(html, "html.parser") print(soup.head.prettify())
copy

Puedes experimentar sustituyendo el atributo .head por .body, por ejemplo. Como se muestra arriba, el elemento <head> abarca varios elementos secundarios. Puedes iterar a través de todos los hijos de los elementos utilizando un bucle for y el atributo .children.

1234567891011121314
# Importing libraries from bs4 import BeautifulSoup from urllib.request import urlopen # Reading web page url = "https://codefinity-content-media.s3.eu-west-1.amazonaws.com/18a4e428-1a0f-44c2-a8ad-244cd9c7985e/jesus.html" page = urlopen(url) html = page.read().decode("utf-8") # Reading HTML with BeautifulSoup soup = BeautifulSoup(html, "html.parser") # Iterating over all element children for child in soup.head.children: print(child)
copy

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2
some-alt