etree.findall: 'OR'-lookup?
Posted
by piquadrat
on Stack Overflow
See other posts from Stack Overflow
or by piquadrat
Published on 2010-03-16T11:29:04Z
Indexed on
2010/03/16
11:36 UTC
Read the original article
Hit count: 302
I want to find all stylesheet definitions in a XHTML file with lxml.etree.findall
. This could be as simple as
elems = tree.findall('link[@rel="stylesheet"]') + tree.findall('style')
But the problem with CSS style definitions is that the order matters, e.g.
<link rel="stylesheet" type="text/css" href="/media/css/first.css" />
<style>body:{font-size: 10px;}</style>
<link rel="stylesheet" type="text/css" href="/media/css/second.css" />
if the contents of the style
tag is applied after the rules in the two link
tags, the result may be completely different from the one where the rules are applied in order of definition.
So, how would I do a lookup that inlcudes both link[@rel="stylesheet"]
and style
?
© Stack Overflow or respective owner