1

I am following the youtube video https://youtu.be/s4jtkzHhLzY and have reached 13:45, when the creator runs his spider. I have followed the tutorial precisely, yet my code refuses to run. This is my actual code. I imported scrapy too as well. Can anyone help me figure out why scrap refuses to acknowledge my spider? The file is in the correct 'spider' file. I am so confused rn.

import scrapy
from scrapy.spiders import Spider
class WhiskeySpider(scrapy.Spider):
   spider_name = 'whiskey'
   start_urls = ['https://www.whiskyshop.com/single-malt-scotch-whisky']

   def parse(self, response):
        for products in response.css('div.product-item-info'):
            yield {
                'name' : products.css('a.product-item-link::text').get(),
                'price' : products.css('span.price::text').get().replace('£',''),
                'link' : products.css('a.product-item-link').attrib['href'],
            }

Photo of my code in VSC

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
lnky
  • 13
  • 4
  • If you are trying to use `scrapy.spiders.Spider`, which you imported, then you just need `class WhiskeySpider(Spider)`. You imported the name as `Spider`. – Tim Roberts Dec 29 '21 at 04:07

2 Answers2

0

spider_name = 'whiskey' should be name = 'whiskey'

SuperUser
  • 4,527
  • 1
  • 5
  • 24
0

The solution that I found was to first, change spider_name to name, and also include my scrapy project inside the venv folder, so that the venv terminal would affect my spider. Thanks so much to @SuperUser and @Tim Roberts for the help.

lnky
  • 13
  • 4