html - Is there any way to get element attribute names by Xpath? -


i can attribute value of element xpath, how attribute names?

example:

# there element '<img src="http://fakesrc" alt="pic name"></img>' = <element img @ 0x102622cb0>  in [10]: i.xpath("//img/@src") out[10]: ['http://fakesrc']  in [11]: i.xpath("//img/@*") out[11]: ['http://fakesrc', 'pic name'] 

how can the names src/alt of i?

depending on whether want include namespace prefixes or not, can choose between following 2 options in xpath 2.0:

//@*/local-name() //@*/name() 

choose different initial context node fits needs , see specifications more info.

with xpath 1.0, above not possible. following does work, show attribute name of 1 attribute, if there multiple ones.

local-name(//@*) name(//@*) 

Comments