diff --git a/scrapy/tests/test_utils_response.py b/scrapy/tests/test_utils_response.py index 3337b80d6..99f1d0ea8 100644 --- a/scrapy/tests/test_utils_response.py +++ b/scrapy/tests/test_utils_response.py @@ -122,6 +122,15 @@ class ResponseUtilsTest(unittest.TestCase): response = TextResponse(url='http://example.com', body=body) self.assertEqual(get_meta_refresh(response), (3, 'http://example.com/')) + # float refresh intervals + body = """""" + response = TextResponse(url='http://example.com', body=body) + self.assertEqual(get_meta_refresh(response), (0.1, 'http://example.com/index.html')) + + body = """""" + response = TextResponse(url='http://example.com', body=body) + self.assertEqual(get_meta_refresh(response), (3.1, 'http://example.com/index.html')) + def test_response_httprepr(self): r1 = Response("http://www.example.com") self.assertEqual(response_httprepr(r1), 'HTTP/1.1 200 OK\r\n\r\n') diff --git a/scrapy/utils/response.py b/scrapy/utils/response.py index a691d8875..0f44a6f5a 100644 --- a/scrapy/utils/response.py +++ b/scrapy/utils/response.py @@ -36,7 +36,7 @@ def get_base_url(response): _baseurl_cache[response] = urljoin_rfc(response.url, match.group(1)) if match else response.url return _baseurl_cache[response] -META_REFRESH_RE = re.compile(ur']*http-equiv[^>]*refresh[^>]*content\s*=\s*(?P["\'])(?P\d+)\s*;\s*url=(?P.*?)(?P=quote)', \ +META_REFRESH_RE = re.compile(ur']*http-equiv[^>]*refresh[^>]*content\s*=\s*(?P["\'])(?P(\d*\.)?\d+)\s*;\s*url=(?P.*?)(?P=quote)', \ re.DOTALL | re.IGNORECASE) _metaref_cache = weakref.WeakKeyDictionary() def get_meta_refresh(response): @@ -51,7 +51,7 @@ def get_meta_refresh(response): body_chunk = remove_comments(remove_entities(response.body_as_unicode()[0:4096])) match = META_REFRESH_RE.search(body_chunk) if match: - interval = int(match.group('int')) + interval = float(match.group('int')) url = safe_url_string(match.group('url').strip(' "\'')) url = urljoin_rfc(response.url, url) _metaref_cache[response] = (interval, url)