Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

call .text from .body_as_unicode() and not the other way around

Mikhail Korobov3e080c3c5272
diff --git a/scrapy/http/response/text.py b/scrapy/http/response/text.py
index 9c667ab7e..afa430329 100644
--- a/scrapy/http/response/text.py
+++ b/scrapy/http/response/text.py
@@ -59,7 +59,12 @@ class TextResponse(Response):
def body_as_unicode(self):
"""Return body as unicode"""
- # check for self.encoding before _cached_ubody just in
+ return self.text
+
+ @property
+ def text(self):
+ """ Body as unicode """
+ # access self.encoding before _cached_ubody to make sure
# _body_inferred_encoding is called
benc = self.encoding
if self._cached_ubody is None:
@@ -67,11 +72,6 @@ class TextResponse(Response):
self._cached_ubody = html_to_unicode(charset, self.body)[1]
return self._cached_ubody
- @property
- def text(self):
- """ Body as unicode """
- return self.body_as_unicode()
-
def urljoin(self, url):
"""Join this Response's url with a possible relative url to form an
absolute interpretation of the latter."""