You can use regex.
Here’s a quick function that takes a path file of a .ma scene and a node to check for its existence:
import re
def object_exists_on_file(path, object_name):
object_exists = False
regex = re.compile('^createNode.+\"({0})\";$'.format(object_name))
with open(path, 'r') as file:
for line in file:
if regex.match(line) is not None:
return True
return False
print object_exists_on_file(file_path, "persp")
# True
You may want to use a regex site to check if your regular expression works against the scenes you have.
There’s also some optimization that could be done but hope you get the general idea of it.