[Python] Warning, how to disable it? "XMLParsedAsHTMLWarning: It looks like you're parsing an...

Discussão em 'Python' iniciado por Stack, Fevereiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    Full text:

    /usr/lib/python3.12/html/parser.py:171: XMLParsedAsHTMLWarning:
    It looks like you're parsing an XML document using an HTML parser.
    If this really is an HTML document (maybe it's XHTML?), you can ignore or filter
    this warning. If it's XML, you should know that using an XML parser will be more
    reliable. To parse this document as XML, make sure you have the lxml package
    installed, and pass the keyword argument `features="xml"` into the BeautifulSoup
    constructor.


    I parse HTML, in this test file:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
    <en-note><div>This is a test note written in the Evernote online editor. it includes some non-ascii characters:<br clear="none"/></div><div><code>—</code> <code>–</code> <code>−</code> € Œ “” ™ œ ž © µ ¶ å õ ý þ ß Ü<br clear="none"/></div></en-note>


    I tried

    from bs4.builder import XMLParsedAsHTMLWarning
    import warnings
    warnings.filterwarnings("ignore", category=XMLParsedAsHTMLWarning)


    Initialization line:

    soup = BeautifulSoup(meta["content"], "html.parser")

    Continue reading...

Compartilhe esta Página