Update sitemap for Python3

Fix sitemap code to work under Python3.

Change-Id: I7aad21f612047ce264b93460f7604b63fa951cab
This commit is contained in:
Andreas Jaeger 2020-03-24 11:13:33 +01:00
parent 5888968ec0
commit b9d280acce
2 changed files with 4 additions and 2 deletions

View File

@ -83,7 +83,8 @@ class ExportSitemap(object):
% spider.domain)) % spider.domain))
with open(os.path.join(os.getcwd(), "sitemap_%s.xml" % spider.domain), with open(os.path.join(os.getcwd(), "sitemap_%s.xml" % spider.domain),
'w') as pretty: 'w') as pretty:
pretty.write(lxml.etree.tostring(tree, pretty_print=True)) pretty.write(lxml.etree.tostring(tree, pretty_print=True,
encoding='unicode'))
def process_item(self, item, spider): def process_item(self, item, spider):
self.exporter.export_item(item) self.exporter.export_item(item)

View File

@ -110,6 +110,7 @@ class SitemapSpider(spiders.CrawlSpider):
timestamp = response.headers['Last-Modified'] timestamp = response.headers['Last-Modified']
else: else:
timestamp = response.headers['Date'] timestamp = response.headers['Date']
lastmod = time.strptime(timestamp, "%a, %d %b %Y %H:%M:%S %Z") lastmod = time.strptime(timestamp.decode("utf-8"),
"%a, %d %b %Y %H:%M:%S %Z")
item['lastmod'] = time.strftime("%Y-%m-%dT%H:%M:%S%z", lastmod) item['lastmod'] = time.strftime("%Y-%m-%dT%H:%M:%S%z", lastmod)
return item return item