diff options
| author | mozbugbox <mozbugbox@yahoo.com.au> | 2015-06-05 19:50:55 +0800 |
|---|---|---|
| committer | mozbugbox <mozbugbox@yahoo.com.au> | 2015-06-05 19:50:55 +0800 |
| commit | 8ae9e1950ce7f6d48b4e6fb71db4206a80210f14 (patch) | |
| tree | b8e1b3321a712cc4dfeca11a138691ea27f7360a /src/lxml/html/soupparser.py | |
| parent | cf15d10de1d8a6bff76d23e588eea4d7bc24e3e2 (diff) | |
| parent | 356a03ace092d9cd8f621e8d41090a0f45c25532 (diff) | |
| download | python-lxml-8ae9e1950ce7f6d48b4e6fb71db4206a80210f14.tar.gz | |
Merge branch 'master' into port-beautifulsoup-v4
Conflicts:
src/lxml/html/soupparser.py
Diffstat (limited to 'src/lxml/html/soupparser.py')
| -rw-r--r-- | src/lxml/html/soupparser.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/lxml/html/soupparser.py b/src/lxml/html/soupparser.py index fbbc63d5..94391bfa 100644 --- a/src/lxml/html/soupparser.py +++ b/src/lxml/html/soupparser.py @@ -5,18 +5,15 @@ __all__ = ["fromstring", "parse", "convert_tree"] import re from lxml import etree, html + try: - from BeautifulSoup import \ - BeautifulSoup, Tag, Comment, ProcessingInstruction, NavigableString, \ - Declaration, CData + from bs4 import ( + BeautifulSoup, Tag, Comment, ProcessingInstruction, NavigableString, Declaration, CData, Doctype) +except ImportError: + from BeautifulSoup import ( + BeautifulSoup, Tag, Comment, ProcessingInstruction, NavigableString, Declaration, CData) class Doctype: pass -except ImportError: - from bs4 import \ - BeautifulSoup, Tag, Comment, ProcessingInstruction, NavigableString, \ - Declaration, CData, Doctype - - def fromstring(data, beautifulsoup=None, makeelement=None, **bsargs): """Parse a string of HTML data into an Element tree using the @@ -32,6 +29,7 @@ def fromstring(data, beautifulsoup=None, makeelement=None, **bsargs): """ return _parse(data, beautifulsoup, makeelement, **bsargs) + def parse(file, beautifulsoup=None, makeelement=None, **bsargs): """Parse a file into an ElemenTree using the BeautifulSoup parser. @@ -46,6 +44,7 @@ def parse(file, beautifulsoup=None, makeelement=None, **bsargs): root = _parse(file, beautifulsoup, makeelement, **bsargs) return etree.ElementTree(root) + def convert_tree(beautiful_soup_tree, makeelement=None): """Convert a BeautifulSoup tree to a list of Element trees. |
