Skip to content

Commit

Permalink
Update approvedfood with config
Browse files Browse the repository at this point in the history
  • Loading branch information
Pce-iyos authored Apr 7, 2024
1 parent b33802c commit d480e04
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@

import logging

import scrapy
from scrapy.selector import Selector
from scrapy.utils.project import get_project_settings
import configparser
import logging
import os

class ApprovedfoodGroceriesSpider(scrapy.Spider):
name = 'approvedfood_groceries'
allowed_domains = ['store.approvedfood.co.uk']
start_urls = ['https://store.approvedfood.co.uk/groceries']

# Initialize logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(name)

# Configurations from config file
config = configparser.ConfigParser()
config_dir = os.path.abspath(os.path.join(os.getcwd(), os.pardir, os.pardir, os.pardir, os.pardir))
config_file_path = os.path.join(config_dir, "config.ini")
config.read(config_file_path)

if 'APPROVEDFOOD' in config:
allowed_domains = [config['APPROVEDFOOD'].get('allowed_domain', '')]
start_urls = [config['APPROVEDFOOD'].get('start_url', '')]
else:
allowed_domains = []
start_urls = []
logger.error("Config section 'APPROVEDFOOD' not found.")

def parse(self, response):
# Extracting the product links...............................
Expand All @@ -29,4 +45,3 @@ def parse_product(self, response):
'Product_Description': response.xpath("//div[@class='pdp_desc']/span/text()").get()
}


0 comments on commit d480e04

Please sign in to comment.