1

This is my spider

class AjaxSpider(BaseSpider):
    name = "AjaxSpider"
    start_urls = ['http://localhost:7908/Test.html'];

    def parse(self, response):
        open('firstResponse', 'wb').write(response.body)
        return [FormRequest.from_response('http://localhost:7908/ToLoadAjax.aspx', callback=self.parseAjax)]

    def parseAjax(self,response):
      open('AjaxResponse', 'wb').write(response.body)

I got this exception:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\internet\base.py", line 1201, in mainLoop
    self.runUntilCurrent()
  File "C:\Python27\lib\site-packages\twisted\internet\base.py", line 824, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 382, in callback
    self._startRunCallbacks(result)
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 490, in _startRunCallbacks
    self._runCallbacks()
--- <exception caught here> ---
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 577, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
  File "testAjax\spiders\Spider.py", line 13, in parse
    return [FormRequest.from_response('http://localhost:7908/ToLoadAjax.aspx', callback=self.parseAjax)]
  File "C:\Python27\lib\site-packages\scrapy-0.20.2-py2.7.egg\scrapy\http\request\form.py", line 35, in from_response
    kwargs.setdefault('encoding', response.encoding)
exceptions.AttributeError: 'str' object has no attribute 'encoding'

I am trying to get the post calls using fromrequest

and I can see the post calls in my chrome webkit xhr.

1 Answer 1

2

It looks like from_response expects a response object. Not a URL string.

Documentation

Sign up to request clarification or add additional context in comments.

1 Comment

So what happens if you use return [FormRequest.from_response(response, callback=self.parseAjax)] instead?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.