Python - import instance of class from module
<p>I have created this class with <code>parse()</code>:</p>

<pre><code>class PitchforkSpider(scrapy.Spider):
    name = "pitchfork_reissues"
    allowed_domains = ["pitchfork.com"]
    #creates objects for each URL listed here
    start_urls = [
                    "http://pitchfork.com/reviews/best/reissues/?page=1",
                    "http://pitchfork.com/reviews/best/reissues/?page=2",
                    "http://pitchfork.com/reviews/best/reissues/?page=3",
    ]

    def parse(self, response):

        for sel in response.xpath('//div[@class="album-artist"]'):
            item = PitchforkItem()
            item['artist'] = sel.xpath('//ul[@class="artist-list"]/li/text()').extract()
            item['reissue'] = sel.xpath('//h2[@class="title"]/text()').extract()

        return item
</code></pre>

<p>then I import the <code>module</code> where the <code>class</code> belongs:</p>

<pre><code>from blogs.spiders.pitchfork_reissues_feed import *
</code></pre>

<p>and try to call <code>parse()</code> in another context:</p>

<pre><code>def reissues(self):

    pitchfork_reissues = PitchforkSpider()
    reissues = pitchfork_reissues.parse('response')
    print (reissues)
</code></pre>

<p>but I get the following error:</p>

<pre><code>pitchfork_reissues.parse('response')
  File "/Users/vitorpatalano/Documents/Code/Soup/Apps/myapp/blogs/blogs/spiders/pitchfork_reissues_feed.py", line 21, in parse
    for sel in response.xpath('//div[@class="album-artist"]'):
AttributeError: 'str' object has no attribute 'xpath'
</code></pre>

<p>what am I missing?</p>

<p>You're calling <code>parse</code> with a string literal:</p>

<pre><code>reissues = pitchfork_reissues.parse('response')
</code></pre>

<p>I guess that should be a variable name? Like so:</p>

<pre><code>reissues = pitchfork_reissues.parse(response)
</code></pre>

<p><strong>Edit</strong></p>

<p>A Spider's <code>parse</code> method requires an instance of <code>scrapy.http.Response</code> as it's first argument, not a string literal that contains the word 'response'.</p>

<p>I haven't used Scrapy myself, so I only know what I read in the documentation, but apparently such a Response instance is usually created by a 'Downloader'.</p>

<p>It seems that you're trying to call your Spider's <code>parse</code> method outside of Scrapy's usual workflow. In that case I think you're responsible for creating such a Response and passing it to your Spider when calling it's <code>parse</code> method.</p>

python class scrapy-spider