added scrapy.utils.response module

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40301
This commit is contained in:
Pablo Hoffman 2008-10-05 07:39:26 +00:00
parent 24df5d1602
commit 7b2317d935
1 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,15 @@
"""
This module provides some useful functions for working with
scrapy.http.Response objects
"""
from scrapy.xpath import XPathSelector
def new_response_from_xpaths(response, xpaths):
"""Return a new response constructed by applying the given xpaths to the
original response body
"""
xs = XPathSelector(response)
parts = [''.join([n for n in xs.x(x).extract()]) for x in xpaths]
new_body = ''.join(parts)
return response.replace(body=new_body)