Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix Python 3 bug with lxml and not-really-strings
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Nov 10, 2016
1 parent 97b068b commit be697bd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions v7/import_page/import_page.py
Expand Up @@ -34,6 +34,7 @@
libextract = None
import lxml.html
import requests
import sys

from nikola.plugin_categories import Command
from nikola import utils
Expand Down Expand Up @@ -70,8 +71,13 @@ def _import_page(self, url):
if 199 < r.status_code < 300: # Got it
# Use the page's title
doc = lxml.html.fromstring(r.content)
title = doc.find('*//title').text_content().decode('utf-8')
slug = utils.slugify(title)
title = doc.find('*//title').text
if sys.version_info[0] == 2 and isinstance(title, str):
title = title.decode('utf-8')
try:
slug = utils.slugify(title, lang='')
except TypeError:
slug = utils.slugify(title)
nodes = list(libextract.api.extract(r.content))
# Let's assume the node with more text is the good one
lengths = [len(n.text_content()) for n in nodes]
Expand Down

0 comments on commit be697bd

Please sign in to comment.