From 7b2317d9358cbe5c35ee78dc56f2a0aad9ac7ece Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sun, 5 Oct 2008 07:39:26 +0000 Subject: [PATCH] added scrapy.utils.response module --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40301 --- scrapy/trunk/scrapy/utils/response.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scrapy/trunk/scrapy/utils/response.py diff --git a/scrapy/trunk/scrapy/utils/response.py b/scrapy/trunk/scrapy/utils/response.py new file mode 100644 index 000000000..63fa3f686 --- /dev/null +++ b/scrapy/trunk/scrapy/utils/response.py @@ -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)