python - IndentationError: unexpected indent on def parse_item(self, response) for scrapy,spider -
i using scrapy information pages of website. here dmoz_spider.py file.when execute indentationerror. please me out.
from scrapy.spider import basespider scrapy.selector import htmlxpathselector scrapy.item import item, field import string scrapy.contrib.spiders import crawlspider, rule scrapy.contrib.linkextractors.sgml import sgmllinkextractor class eypitem(item): title = field() link = field() price = field() review = field() class eypspider(crawlspider): name = "dmoz" allowed_domains =["http://www.walgreens.com"] start_urls =["http://www.walgreens.com/search/results.jsp?ntt=allergy%20medicine"] rules = (rule(sgmllinkextractor(allow=('/search/results\.jsp', )), callback='parse_item', follow= true),) def parse_item(self, response): self.log('hi, item page! %s' % response.url) hxs = htmlxpathselector(response) sites = hxs.select('//div[@id="productgrid"]') items = [] site in sites: iteme = eypitem() iteme["title"] = site.select('//*[@class="image-container"]/a/img/@alt').extract() iteme["link"] = site.select('//*[@class="image-container"]/a/img/@src').extract() iteme["price"] = site.select('//*[@class="pricing"]/div/p/text()').extract() iteme["review"] = site.select('//*[@class="reviewsnippet"]/div/div/span/text()').extract() items.append(iteme) return items
indent lines below
def parse_item(self, response): self.log('hi, item page! %s' % response.url)
to this
def parse_item(self, response): self.log('hi, item page! %s' % response.url) hxs = htmlxpathselector(response) sites = hxs.select('//div[@id="productgrid"]') items = [] site in sites: iteme = eypitem() iteme["title"] = site.select('//*[@class="image-container"]/a/img/@alt').extract() iteme["link"] = site.select('//*[@class="image-container"]/a/img/@src').extract() iteme["price"] = site.select('//*[@class="pricing"]/div/p/text()').extract() iteme["review"] = site.select('//*[@class="reviewsnippet"]/div/div/span/text()').extract() items.append(iteme) return items
Comments
Post a Comment