TextResponse.follow_all: Simplify implementation

This commit is contained in:
Eugenio Lacuesta 2019-10-15 11:52:12 -03:00
parent 9d5398e7f2
commit 2a4d4a466a
No known key found for this signature in database
GPG Key ID: DA3EF2D0913E9810
1 changed files with 5 additions and 7 deletions

View File

@ -191,14 +191,12 @@ class TextResponse(Response):
if arg_count != 1:
raise ValueError('Please supply exactly one of the following arguments: urls, css, xpath')
if not urls:
urls = []
if css:
selector_method = getattr(self, 'css')
expression = css
elif xpath:
selector_method = getattr(self, 'xpath')
expression = xpath
for selector in selector_method(expression):
selector_list = self.css(css)
if xpath:
selector_list = self.xpath(xpath)
urls = []
for selector in selector_list:
try:
urls.append(_url_from_selector(selector))
except ValueError: