I’m trying to get rid of all data- attributes in a document. If my document looks like
<div id="person" data-name="John Smith" data-age="32" data-location="UK">...</div>
I want to strip out the data to just leave
<div id="person">...</div>
I’ve tried a lot of combinations, and can a least get to things like data-name with
doc.xpath('//@data-name')
but sometimes, there will be more data-? properties, and I’d like to avoid manually adding them all. This SO answer is close, but it’s not returning anything for me when I try
doc.xpath("//*[@*[contains(., 'data-')]]")
To select all attributes whose name starts with
data-: