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,6 +18,9 @@ class BeautifulSoupParser(ParserBase):
|
||||
@cached_property
|
||||
def soup(self):
|
||||
try:
|
||||
if six.PY3:
|
||||
from bs4 import BeautifulSoup
|
||||
else:
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
return BeautifulSoup(self.content)
|
||||
except ImportError as err:
|
||||
@@ -25,9 +29,15 @@ class BeautifulSoupParser(ParserBase):
|
||||
raise ParserError("Error while initializing Parser: %s" % err)
|
||||
|
||||
def css_elems(self):
|
||||
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):
|
||||
if six.PY3:
|
||||
return self.soup.find_all('script')
|
||||
else:
|
||||
return self.soup.findAll('script')
|
||||
|
||||
def elem_attribs(self, elem):
|
||||
|
||||
Reference in New Issue
Block a user