Ich möchte aus folgendem Html:
Folgendes rausholen:<h1 id="eins">Titel1</h1>
<h2>Untertitel 1</h2>
<p>Blah 1 Blah 1 Blah 1</p>
<p> mehr Blah1</p>
<p> noch mehr Blah1</p>
<h1 id="zwei">Titel2</h1>
<h2>Untertitel 2</h2>
<p>Blah 2 Blah 2 Blah 2</p>
<p> mehr Blah2</p>
<h1 id="n"> Titeln</h1>
....
Id : eins
Titel: Titel1
Utitel: Untertitel1
Desc: Blah1 ... Nur das erste <p>-Tag!
Id : zwei
Titel: Titel2
Utitel: Untertitel2
Desc: Blah2 ...
...
Es tut mir leid, ich hab ein fürchterliches Brett vor dem Kopf.
Mit sowas wie:
Code: Alles auswählen
from BeautifulSoup import BeautifulSoup
html = """ der_Kram_oben"""
soup = BeautifulSoup(html)
for h1 soup("h1"):
print "Id: ", dict(h1.attrs).get("id")
print "Titel: ", h1.string
for h2 soup("h2"):
print "Utitel: ", h2.string
for p soup("p"):
print "Desc: ", p.string
Ich habe mich schon durch die BeautifulSoup-Doku gefressen und einiges ausprobiert, aber irgendwie hab ich ein totales Brett vorm Kopf.
Vielen Dank für Euren Hirnschmalz, mir ist es heute leider nicht vergönnt.
dcc
PS: Ich weiß, daß die Lösung in der Doku liegt und wahrscheinlich recht einfach ist. Ich sehe sie aber einfach nicht!