Sorry for the newbie question i'm just trying to get to grips and everything was going well until i got stuck on this as it's not giving me any errors just giving no result.
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
start_urls = [
'https://www.currys.co.uk/gbuk/computing/tablets-and-ereaders/tablets/149_3402_32003_xx_xx/xx-criteria.html',
]
def parse(self, response):
for quote in response.xpath('//*[@class="product"]'):
yield {
'title': quote.xpath('//*[@class="productTitle"]').extract_first(),
'price': quote.xpath('//*[@class="price"]').extract_first(),
'image': quote.xpath('//*[@class="product-images"]/img/@src').extract(),
}
Been working from the https://doc.scrapy.org/ and just a little stuck with this one, any advice would be amazing and possibly if there is any error handling that could help along the way.
Thanks!
答案 0 :(得分:3)
您的parse
方法应缩进为QuotesSpider
类的成员:
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
start_urls = [
'https://www.currys.co.uk/gbuk/computing/tablets-and-ereaders/tablets/149_3402_32003_xx_xx/xx-criteria.html',
]
def parse(self, response):
self.log('In parse!')
for quote in response.xpath('//*[@class="product"]'):
self.log('Yielding {}!'.format(quote))
yield {
'title': quote.xpath('//*[@class="productTitle"]').extract_first(),
'price': quote.xpath('//*[@class="price"]').extract_first(),
'image': quote.xpath('//*[@class="product-images"]/img/@src').extract(),
}