for item in oeb.spine: for a in item.data.xpath('//*[local-name()="a" and @href]'): href = a.get('href') a.set('href', mapping[href])