mirror of https://github.com/scrapy/scrapy.git
added scrapy.utils.response module
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40301
This commit is contained in:
parent
24df5d1602
commit
7b2317d935
|
|
@ -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)
|
||||
Loading…
Reference in New Issue