In python3 import bs4 not BeautifulSoup which will work only in python2
This commit is contained in:
@@ -4,6 +4,7 @@ from django.core.exceptions import ImproperlyConfigured
|
||||
from compressor.exceptions import ParserError
|
||||
from compressor.parser import ParserBase
|
||||
from compressor.utils.decorators import cached_property
|
||||
from django.utils import six
|
||||
|
||||
try:
|
||||
from django.utils.encoding import smart_text
|
||||
@@ -17,7 +18,10 @@ class BeautifulSoupParser(ParserBase):
|
||||
@cached_property
|
||||
def soup(self):
|
||||
try:
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
if six.PY3:
|
||||
from bs4 import BeautifulSoup
|
||||
else:
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
return BeautifulSoup(self.content)
|
||||
except ImportError as err:
|
||||
raise ImproperlyConfigured("Error while importing BeautifulSoup: %s" % err)
|
||||
@@ -25,10 +29,16 @@ class BeautifulSoupParser(ParserBase):
|
||||
raise ParserError("Error while initializing Parser: %s" % err)
|
||||
|
||||
def css_elems(self):
|
||||
return self.soup.findAll({'link': True, 'style': True})
|
||||
if six.PY3:
|
||||
return self.soup.find_all({'link': True, 'style': True})
|
||||
else:
|
||||
return self.soup.findAll({'link': True, 'style': True})
|
||||
|
||||
def js_elems(self):
|
||||
return self.soup.findAll('script')
|
||||
if six.PY3:
|
||||
return self.soup.find_all('script')
|
||||
else:
|
||||
return self.soup.findAll('script')
|
||||
|
||||
def elem_attribs(self, elem):
|
||||
return dict(elem.attrs)
|
||||
|
||||
Reference in New Issue
Block a user