2๐
โ
You get a tuple because you supply a tuple (the parentheses) as the default return value for url.get()
. Supply an empty string, and you can use its .endswith()
method. Also note that the element itself has a get()
method to retrieve attribute values (you do not have to go via .attrib
). Example:
if i.get('Href', '').endswith('.jpg'):
result.append(i.attrib)
๐คSteven
Source:stackexchange.com