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'
무엇이 누락 되었습니까?
:'재발행 = pitchfork_reissues.parse (응답) 나가서 설명하자면 NameError : –
그럼 당신이 (appearantly "다운로드되는 scrapy.http.Response 인스턴스를 필요 defined'되지 전역 이름 '응답' 다운로더에 의해) ". [the docs] (http://doc.scrapy.org/ko/latest/topics/request-response.html#response-objects)를 참조하십시오 :) – Jasper