Seite 1 von 1

Reguläre Ausdrücke über mehrere Zeilen

Verfasst: Dienstag 10. August 2004, 14:38
von Nappio
Hallo,

aus einer HTML-Datei will ich folgendes auslesen:
.
.
.
<td valign="bottom">&nbsp;</td>
<td>DIESEN TEXT WILL ICH</td>

<td valign="bottom">&nbsp;</td>
<td>DIESEN TEXT WILL ICH</td>

<td valign="bottom">&nbsp;</td>
<td>DIESEN TEXT WILL ICH</td>
.
.
Aber
pat=re.compile(r"<td valign="bottom">&nbsp;</td><td>(.*?)</td>",re.I)

findet es nicht. Kann mir jemand helfen?

Danke!

Verfasst: Dienstag 10. August 2004, 15:01
von mawe
Hi!
Nappio hat geschrieben: findet es nicht
Kann es auch nicht, weil ein \n zwischen </tb> und <tb> steht.
Reicht in diesem Fall nicht:

Code: Alles auswählen

import re

f = file("datei.html","r")

pat = re.compile(r'<td>([\w\s]+?)</td>')
for line in f.readlines():
	m = pat.match(line)
	if m:
		print m.groups()

Gruß, mawe

Danke

Verfasst: Dienstag 10. August 2004, 15:03
von Nappio
danke jetzt geht es