diff --git a/scrapy/tests/test_utils_sitemap.py b/scrapy/tests/test_utils_sitemap.py index 331888753..762ebe0ed 100644 --- a/scrapy/tests/test_utils_sitemap.py +++ b/scrapy/tests/test_utils_sitemap.py @@ -56,6 +56,28 @@ class SitemapTest(unittest.TestCase): +""") + self.assertEqual(list(s), + [{'priority': '1', 'loc': 'http://www.example.com/', 'lastmod': '2009-08-16', 'changefreq': 'daily'}, + {'loc': 'http://www.example.com/2', 'lastmod': ''}, + ]) + + def test_sitemap_wrong_ns(self): + """We have seen sitemaps with wrongs ns. Presumably, Google still works + with these, though is not 100% confirmed""" + s = Sitemap(""" + + + http://www.example.com/ + 2009-08-16 + daily + 1 + + + http://www.example.com/2 + + + """) self.assertEqual(list(s), [{'priority': '1', 'loc': 'http://www.example.com/', 'lastmod': '2009-08-16', 'changefreq': 'daily'}, diff --git a/scrapy/utils/sitemap.py b/scrapy/utils/sitemap.py index d0157d397..2a496f719 100644 --- a/scrapy/utils/sitemap.py +++ b/scrapy/utils/sitemap.py @@ -22,7 +22,8 @@ class Sitemap(object): for elem in self._root.getchildren(): d = {} for el in elem.getchildren(): - _, name = el.tag.split('}', 1) + tag = el.tag + name = tag.split('}', 1)[1] if '}' in tag else tag d[name] = el.text.strip() if el.text else '' yield d