浏览代码

[sitemap] if last-modified not set in header use current date

This solves the following issue when last-modified is not set in the
response header:

---snip---
KeyError: 'Last-Modified'
---snap---

Change-Id: I372f9638f6b5006ff250b9dbe0e75cc1556d18c2
tags/0.32.0
Christian Berendt 4 年前
父节点
当前提交
6b5b7d530a
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5
    2
      sitemap/generator/spiders/sitemap.py

+ 5
- 2
sitemap/generator/spiders/sitemap.py 查看文件

@@ -72,7 +72,10 @@ class SitemapSpider(spiders.CrawlSpider):
if path.startswith("/%s" % entry):
item['changefreq'] = 'weekly'

lastmod = time.strptime(response.headers['Last-Modified'],
"%a, %d %b %Y %H:%M:%S %Z")
if 'Last-Modified' in response.headers:
timestamp = response.headers['Last-Modified']
else:
timestamp = response.headers['Date']
lastmod = time.strptime(timestamp, "%a, %d %b %Y %H:%M:%S %Z")
item['lastmod'] = time.strftime("%Y-%m-%dT%H:%M:%S%z", lastmod)
return item

正在加载...
取消
保存