Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7506323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:13:33+00:00 2026-05-29T22:13:33+00:00

Which one is better and more useful for malformed html? I cannot find how

  • 0

Which one is better and more useful for malformed html?
I cannot find how to use libxml2.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:13:33+00:00Added an answer on May 29, 2026 at 10:13 pm

    In the libxml2 page you can see this note:

    Note that some of the Python purist dislike the default set of Python bindings, rather than complaining I suggest they have a look at lxml the more pythonic bindings for libxml2 and libxslt and check the mailing-list.

    and in the lxml page this other one:

    The lxml XML toolkit is a Pythonic binding for the C libraries libxml2 and libxslt. It is unique in that it combines the speed and XML feature completeness of these libraries with the simplicity of a native Python API, mostly compatible but superior to the well-known ElementTree API.

    So essentially, with lxml you get exactly the same functionality,
    but with a a pythonic API compatible with the ElementTree library in the standard library (so this means the standard library documentation will be useful to learn how to use lxml). That’s why, lxml is preferred over libxml2 (even when the underlying implementation is the same one).

    Edit: Having said that, as other answers explain, to parse malformed html your best option is to use BeautifulSoup. One interesting thing to note is that, if you have installed lxml, BeautifulSoup will use it as explained in the documentation for the new version:

    If you don’t specify anything, you’ll get the best HTML parser that’s installed. Beautiful Soup ranks lxml’s parser as being the best, then html5lib’s, then Python’s built-in parser.

    Anyway, even if BeautifulSoup uses lxml under the hood, you’ll be able to parse broken html that you can’t parse with xml directly. For example:

    >>> lxml.etree.fromstring('<html>')
    ...
    XMLSyntaxError: Premature end of data in tag html line 1, line 1, column 7
    

    However:

    >>> bs4.BeautifulSoup('<html>', 'lxml')
    <html></html>
    

    Finally, note that lxml also provides an interface to the old version of BeautifulSoup as follows:

    >>> lxml.html.soupparser.fromstring('<html>')
    <Element html at 0x13bd230>
    

    So at the end of the day, you’ll probably be using lxml and BeautifulSoup anyway. The only thing you’ve got to choose is what’s the API that you like the most.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which one is better to use when it come to return value for example
If there is more then one implementation, which one is better/mostly maintained? Specifically for
I pretty much don't know anything about these two. Which one is better/more efficient
I'm just wondering which one is better, or more recommended for processing form data.
Which one performs better to run a game main loop?
Which one is better when performance is taken into consideration an if else if
Which one is better (implicit control flow via return or control flow via if
which one is better for implementing chat for the iPhone with users in the
Which one is better/faster/preferred 1: mov eax, 5 push eax mov eax, [someAddress] push
Which one is better from performance view user control or custom control? Right now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.