From a5ff6abf566b950d7ab3d1a45f1ecf2ba66d0068 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sat, 14 Mar 2026 13:45:15 -0400 Subject: [PATCH] [foods] Add catch for common domain exclusions --- vrobbler/apps/foods/constants.py | 3 +++ vrobbler/apps/foods/sources/rscraper.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 vrobbler/apps/foods/constants.py diff --git a/vrobbler/apps/foods/constants.py b/vrobbler/apps/foods/constants.py new file mode 100644 index 0000000..67f8f76 --- /dev/null +++ b/vrobbler/apps/foods/constants.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python3 + +EXCLUDED_FOOD_DOMAINS = ["bbc.co.uk", "bbc.com", "www.bbc.com"] diff --git a/vrobbler/apps/foods/sources/rscraper.py b/vrobbler/apps/foods/sources/rscraper.py index 48d5511..317f8aa 100644 --- a/vrobbler/apps/foods/sources/rscraper.py +++ b/vrobbler/apps/foods/sources/rscraper.py @@ -1,11 +1,17 @@ +import logging +from typing import Dict, List, Optional +from urllib.parse import urlparse + +import requests +from django.core.files.base import ContentFile +from foods.constants import EXCLUDED_FOOD_DOMAINS from recipe_scrapers import scrape_html from recipe_scrapers._exceptions import ( NoSchemaFoundInWildMode, SchemaOrgException, ) -import requests -from typing import Dict, Optional, List -from django.core.files.base import ContentFile + +logger = logging.getLogger(__name__) class RecipeScraperService: @@ -73,6 +79,10 @@ class RecipeScraperService: @classmethod def is_recipe_url(cls, url: str) -> bool: """Check if a URL points to a recipe by fetching and checking the HTML.""" + domain = urlparse(url).netloc + if domain in EXCLUDED_FOOD_DOMAINS and "food" not in url: + logger.info("[food] domain found in EXCLUDED_FOOD_DOMAINS") + return False try: response = requests.get( url, @@ -86,7 +96,6 @@ class RecipeScraperService: return False return cls.is_recipe(response.text, url) except Exception as e: - print(e) return False def _safe_call(self, scraper, method, default=None):