[Python-de] HTML mit RegEx filtern
Gerold Penz
gerold.penz at tirol.utanet.at
Mi Dez 20 23:44:03 CET 2006
Stefan Antonelli schrieb:
> Hast Du vielleicht ein oder zwei Links
Hi Stefan!
Beispiele:
http://www.python-forum.de/post-27658.html
http://www.python-forum.de/post-37269.html#37269
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
from BeautifulSoup import BeautifulSoup
html = """<html>
<head>
<title>Hallo Welt</title>
</head>
<body>
<img src="http://www.bcom.at/image1.gif">
<img src="http://www.bcom.at/image2.gif" />
<img srcccc="http://www.bcom.at/image3.gif" />
</body>
</html>
"""
soup = BeautifulSoup(html)
for image in soup("img"):
try:
print "src Methode1:", image["src"]
except KeyError:
print None
print "src Methode2:", image.get("src")
print "src Methode3:", dict(image.attrs).get("src")
print
mfg
Gerold
:-)
--
________________________________________________________________________
Gerold Penz - bcom - Programmierung
gerold.penz at tirol.utanet.at | http://gerold.bcom.at | http://sw3.at
Ehrliche, herzliche Begeisterung ist einer der
wirksamsten Erfolgsfaktoren. Dale Carnegie