(Python) AttributeError: ‘NoneType’ object has no attribute ‘text’

Instead of checking if child.find(‘EmentaMateria’).text is not None, you should make sure that child.find(‘EmentaMateria’) is not None first. Also, you should store the returning value of child.find(‘EmentaMateria’) to avoid calling it twice. Lastly, you should assign ementa a default value if child.find(‘EmentaMateria’) is None; otherwise your print function below will be referencing an un-initialized variable. Change: to: Alternatively, you can use the built-in function getattr to do the same without a temporary variable: