Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:54:37+00:00 2026-06-17T14:54:37+00:00

I wrote a spider, that worked brilliantly the first time. The second time I

  • 0

I wrote a spider, that worked brilliantly the first time. The second time I tried to run it, it didn’t venture beyond the start_urls. I tried to fetch the url in scrapy shell and create a HtmlXPathSelector object from the returned response. That is when I got the error

So the steps were:
`

[scrapy shell] fetch('http://example.com') #its something other than example.
[scrapy shell] from scrapy.selector import HtmlXPathSelector
[scrapy shell] hxs = HtmlXPathSelector(response)

---------------------------------------------------------------------------

Traceback:

AttributeError                            Traceback (most recent call last)
<ipython-input-3-a486208adf1e> in <module>()
----> 1 HtmlXPathSelector(response)

/home/codefreak/project-r42catalog/env-r42catalog/lib/python2.7/site-packages/scrapy/selector/lxmlsel.pyc in __init__(self, response, text, namespaces, _root, _expr)
     29                 body=unicode_to_str(text, 'utf-8'), encoding='utf-8')
     30         if response is not None:
---> 31             _root = LxmlDocument(response, self._parser)
     32 
     33         self.namespaces = namespaces

/home/codefreak/project-r42catalog/env-r42catalog/lib/python2.7/site-packages/scrapy/selector/lxmldocument.pyc in __new__(cls, response, parser)
     25         if parser not in cache:
     26             obj = object_ref.__new__(cls)
---> 27             cache[parser] = _factory(response, parser)
     28         return cache[parser]
     29 

/home/codefreak/project-r42catalog/env-r42catalog/lib/python2.7/site-packages/scrapy/selector/lxmldocument.pyc in _factory(response, parser_cls)
     11 def _factory(response, parser_cls):
     12     url = response.url
---> 13     body = response.body_as_unicode().strip().encode('utf8') or '<html/>'
     14     parser = parser_cls(recover=True, encoding='utf8')
     15     return etree.fromstring(body, parser=parser, base_url=url)

Error:

AttributeError: 'Response' object has no attribute 'body_as_unicode'

Am I overlooking something very obvious or stumbled upon a bug in scrapy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:54:39+00:00Added an answer on June 17, 2026 at 2:54 pm

    body_as_unicode is a method of TextResponse. TextResponse, or one of its subclasses such as HtmlResponse, will be created by scrapy if the http response contains textual content.

    In [1]: fetch('http://scrapy.org')
    ...
    In [2]: type(response)
    Out[2]: scrapy.http.response.html.HtmlResponse
    ...
    In [3]: fetch('http://www.scrapy.org/site-media/images/logo.png')
    ...
    In [4]: type(response)
    Out[4]: scrapy.http.response.Response
    

    In your case, the most likely explanation is that scrapy believes the response does not contain text.

    Does the HTTP response from the server correctly set the Content-Type header? Does it render correctly in a browser? These questions will help understand if it’s expected behavior or a bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A (long) while ago I wrote a web-spider that I multithreaded to enable concurrent
I wrote a code that shows a figure devided to 2 parts; the first
I am working on scrapy, i am scheduling a spider i had wrote with
I wrote a PHP script that retrieves values from a MySQL Query. I used
I wrote a Flickr search engine that makes a call to either a public
Using the second answer to this question I wrote a code for a 4
I need to create a spider that crawls for some data from web site.
I wrote a simple jquery slider that basically goes through 3 divs, hidding one
I have spider that I have written using the Scrapy framework. I am having
YES, I have been looking for answers and couldn't find anything that worked or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.