“Parent de BeautifulSoup” Réponses codées

BeautifulSoup Find Class

mydivs = soup.findAll("div", {"class": "stylelistrow"})
Tommyom

Enfants Belle soupe

li = soup.find('li', {'class': 'text'})
children = li.findChildren("a" , recursive=False)
for child in children:
    print child
Long Lyrebird

BeautifulSoup Get Parent Element

>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup('<p>TEXT I WANT <i> – </i></p>')
>>> soup.find('i').parent
<p>TEXT I WANT <i> – </i></p>
>>> soup.find('i').parent.text
u'TEXT I WANT  \u2013 '
Disgusted Dugong

Parent de BeautifulSoup

from bs4 import BeautifulSoup

# Html source
html = """
<section>
<div>
<h2>Recent Posts:</h2>
</div>
</section>
"""

# Parse
soup = BeautifulSoup(html, 'html.parser')

# Get h2 tag
h2 = soup.h2

# Print h2 parent
print(h2.parent)
Cooperative Cicada

Réponses similaires à “Parent de BeautifulSoup”

Questions similaires à “Parent de BeautifulSoup”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code