有没有用美丽的汤解析XML比单独使用lxml的有什么好处? [英] Are there any benefits of using Beautiful Soup to parse XML over using lxml alone?

查看:418
本文介绍了有没有用美丽的汤解析XML比单独使用lxml的有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用美丽的汤经常来解析HTML文件,所以当我最近需要解析XML文件,我选择使用它。但是,因为我解析一个非常大的文件时,它失败了。当研究为什么会失败,我被带到了这个问题:<一href=\"http://stackoverflow.com/questions/14924200/loading-huge-xml-files-and-dealing-with-memoryerror\">Loading巨大的XML文件和处理的MemoryError 。

I use Beautiful Soup often to parse HTML files, so when I recently needed to parse an XML file, I chose to use it. However, because I'm parsing an extremely large file, it failed. When researching why it failed, I was led to this question: Loading huge XML files and dealing with MemoryError.

这使我对我的问题:如果LXML可以处理大型文件和美丽的汤不能,有没有用美丽的汤,而不是简单地使用直接使用lxml的任何好处。

This leads me to my question: If lxml can handle large files and Beautiful Soup cannot, are there any benefits of using Beautiful Soup instead of simply using using lxml directly?

推荐答案

如果你看一下关于 BeautifulSoup解析器

BeautifulSoup是一个分析Python包的的HTML,而LXML这样做快,但高品质的HTML / XML。所以,如果你正在处理的第一个你和BS最好... 有LXML的好处是,你能够获得 soupparser

"BeautifulSoup" is a Python package that parses broken HTML, while "lxml" does so faster but with high quality HTML/XML. So if you're dealing with the first one you're better off with BS... but the advantage of having "lxml" is that you're able to get the soupparser.

从我在上面提供的链接,它表明你如何与LXML

From that link I provided at the top it shows how you can use the capabilities of "BS" with "lxml"

那么,到底 ...你是LXML更好。

So in the end... you are better off with "lxml".

这篇关于有没有用美丽的汤解析XML比单独使用lxml的有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆