You can use something like this:
find . -type f -name '*q2*.html' -execdir sh -c '
your/script "$1" > invalid.txt
grep -q "Error:" invalid.txt || mv invalid.txt valid.txt
' sh {} \;
Note that you will be overwriting the (in)valid.txt file if you have more than one html files matching your find, into the same directory. You would probably like to include $(basename "$1") into the output file namefilename to make its name unique per directory.
With -execdir, the command is executed into the directory of every file found.
grep -q silently exits with failure (1) if no Error: found, so the command after || is executed. If error found, grep exits with success (0) and the mv is not executed.
You probably want to add some more for catching cases like some error of your script. Also ensure that the search pattern cannot exist for a valid file.
Another approach, independent of what messages your program is printing, is to use exit codes.
import sys to your python script and use sys.exit(0) for a valid file, or sys.exit(42) for an invalid one. After execution, you parse the exit code ($?) and decide what to do.
See also: https://tldp.org/LDP/abs/html/exitcodes.html
Example:
your/script "$1" > output.txt
result=$?
((result == 0)) && do stuff for valid file
((result == 42)) && do stuff for invalid file