0
からクラスの輸入インスタンス私はparse()
でこのクラスを作成しました:パイソン - モジュール
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
、私はclass
が所属module
をインポートします。
from blogs.spiders.pitchfork_reissues_feed import *
と別でparse()
を呼び出そう状況:
def reissues(self):
pitchfork_reissues = PitchforkSpider()
reissues = pitchfork_reissues.parse('response')
print (reissues)
次のエラーが表示されます。
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'
何が紛れていますか?
これは私に以下のトレースバックを与えます: 'reissues = pitchfork_reissues.parse(レスポンス) NameError:グローバル名 'レスポンス'が定義されていません –
まあ、scrapy.http.Responseインスタンスが必要です。ダウンローダによって)」。 [the docs](http://doc.scrapy.org/ja/latest/topics/request-response.html#response-objects)を参照してください:) – Jasper