Ich benutze BeautifulSoup4 mit Python, um Inhalt aus dem Web zu scrape, mit dem ich Inhalt von bestimmten HTML-Tags extrahieren möchte, während ich andere ignoriere.Erhalte bestimmte Tags innerhalb des Eltern-Tags mit Beautifulsoup4
Ich habe folgende html:
<div class="the-one-i-want">
<p>
"random text content here and about"
</p>
<p>
"random text content here and about"
</p>
<p>
"random text content here and about"
</p>
<div class="random-inserted-element-i-dont-want">
<content>
</div>
<p>
"random text content here and about"
</p>
<p>
"random text content here and about"
</p>
</div>
Mein Ziel ist es zu verstehen, wie Python aus der Mutter erhält die <p>
Elemente nur instruieren <div> class="the-one-i-want">
, sonst innerhalb all <div>
‚s zu ignorieren.
Derzeit bin ich den Inhalt des übergeordneten div durch das folgende Verfahren Ortung:
content = soup.find('div', class_='the-one-i-want')
Allerdings kann ich nicht scheinen, um herauszufinden, wie weiter zu spezifizieren nur aus, dass die <p>
Tags zu extrahieren, ohne Error.
Ich schwöre, dass ich das schon versucht hatte, aber ich denke nicht. Problem gelöst. Vielen Dank – theeastcoastwest