Disable warnings when loading non-well-formed HTML by DomDocument (PHP)

Call libxml_use_internal_errors(true); prior to processing with with $xmlDoc->loadHTML() This tells libxml2 not to send errors and warnings through to PHP. Then, to check for errors and handle them yourself, you can consult libxml_get_last_error() and/or libxml_get_errors() when you’re ready: libxml_use_internal_errors(true); $dom->loadHTML($html); $errors = libxml_get_errors(); foreach ($errors as $error) { // handle the errors as you wish … Read more

What’s the difference between logging.warn and logging.warning in Python?

logging.warn has been deprecated since Python 3.3 and you should use logging.warning. Prior to Python 3.3, logging.warn and logging.warning were the same function, but logging.warn was not documented, as noted in a closed issue in the Python bug tracker http://bugs.python.org/issue13235: That’s deliberate. The original code (before incorporation into Python) had warn(), which was kept for … Read more

Get Traceback of warnings

You can get what you want by assigning to warnings.showwarning. The warnings module documentation itself recommends that you do that, so it’s not that you’re being tempted by the dark side of the source. 🙂 You may replace this function with an alternative implementation by assigning to warnings.showwarning. You can define a new function that … Read more