Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

fixed minor bug in sitemap parser

Pablo Hoffman574b070bb457
diff --git a/scrapy/tests/test_utils_sitemap.py b/scrapy/tests/test_utils_sitemap.py
index fc1f3b15f..331888753 100644
--- a/scrapy/tests/test_utils_sitemap.py
+++ b/scrapy/tests/test_utils_sitemap.py
@@ -51,10 +51,16 @@ class SitemapTest(unittest.TestCase):
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
+ <url>
+ <loc> http://www.example.com/2</loc>
+ <lastmod />
+ </url>
</urlset>
""")
self.assertEqual(list(s),
- [{'priority': '1', 'loc': 'http://www.example.com/', 'lastmod': '2009-08-16', 'changefreq': 'daily'}])
+ [{'priority': '1', 'loc': 'http://www.example.com/', 'lastmod': '2009-08-16', 'changefreq': 'daily'},
+ {'loc': 'http://www.example.com/2', 'lastmod': ''},
+ ])
def test_sitemap_urls_from_robots(self):
robots = """User-agent: *
diff --git a/scrapy/utils/sitemap.py b/scrapy/utils/sitemap.py
index e8d3b367e..d0157d397 100644
--- a/scrapy/utils/sitemap.py
+++ b/scrapy/utils/sitemap.py
@@ -23,7 +23,7 @@ class Sitemap(object):
d = {}
for el in elem.getchildren():
_, name = el.tag.split('}', 1)
- d[name] = el.text.strip()
+ d[name] = el.text.strip() if el.text else ''
yield d
def sitemap_urls_from_robots(robots_text):