mirror of https://github.com/scrapy/scrapy.git
Response.follow_all: return empty generators for empty sequences
This commit is contained in:
parent
388f23c30c
commit
8d30dc0888
|
|
@ -188,9 +188,11 @@ class TextResponse(Response):
|
|||
selectors from which links cannot be obtained (for instance, anchor tags without an
|
||||
``href`` attribute)
|
||||
"""
|
||||
arg_count = len(list(filter(None, (urls, css, xpath))))
|
||||
if arg_count != 1:
|
||||
raise ValueError('Please supply exactly one of the following arguments: urls, css, xpath')
|
||||
arguments = [x for x in (urls, css, xpath) if x is not None]
|
||||
if len(arguments) != 1:
|
||||
raise ValueError(
|
||||
"Please supply exactly one of the following arguments: urls, css, xpath"
|
||||
)
|
||||
if not urls:
|
||||
if css:
|
||||
urls = self.css(css)
|
||||
|
|
|
|||
|
|
@ -215,6 +215,10 @@ class BaseResponseTest(unittest.TestCase):
|
|||
links = map(Link, absolute)
|
||||
self._assert_followed_all_urls(links, absolute)
|
||||
|
||||
def test_follow_all_empty(self):
|
||||
r = self.response_class("http://example.com")
|
||||
self.assertEqual([], list(r.follow_all([])))
|
||||
|
||||
def test_follow_all_invalid(self):
|
||||
r = self.response_class("http://example.com")
|
||||
if self.response_class == Response:
|
||||
|
|
|
|||
Loading…
Reference in New Issue