Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python xlxml xpath expression to match substring in attribute

Tags:

python

xpath

lxml

Let's say I have the below XML

<root>
   <element class="Page" style="background: url(/images/RlEguQY3_ghsdr.png?1324483033) repeat left top;" />
   <element class="User" />
   <element class="Image" src="/images/bg.png" />
</root>

I am looking for a xpath expression which 1) matches all elements that have /images in the style attribute and 2) matches all Image elements that have /images in the src attribute

Any help greatly appreciated

Thanks

like image 980
Thomas Avatar asked Dec 21 '11 16:12

Thomas


1 Answers

 //element[contains(@style, '/images') or (@class='Image' and contains(@src, '/images'))]

(or something similar) should do it.

like image 119
hcayless Avatar answered Sep 23 '22 18:09

hcayless