Beautiful Soup Looping Extraction Question
stefan_ml at behnel.de
Tue Mar 25 19:50:12 CET 2008
again, not BS related, but still a solution.
> Let's say I have a file that looks at file.html pasted below.
> My goal is to extract all elements where the following is true: <p
> align="left"> and <div align="center">.
from lxml import html
tree = html.parse("file.html")
for el in tree.iter():
if el.tag == 'p' and el.get('align') == 'left':
elif el.tag == 'div' and el.get('align') == 'center':
I assume that BS can do something similar, though.
More information about the Python-list