Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better nutrition parsing for cookwell.com #1459

Merged
merged 5 commits into from
Jan 14, 2025

Conversation

eric-hoffmann
Copy link
Contributor

Cookwell.com only provides calorie information in the recipe metadata, but additional nutrition information is embedded in one of the page's scripts. This change searches the script tags for the matching information and extracts it. If it cannot find the information, it will default to the calorie only information provided in the metadata. I've tested this with a few random recipes from the site and observed it working as expected.

from urllib.request import urlopen
from recipe_scrapers import scrape_html
url = "https://cookwell.com/recipe/crispy-oven-fries"
html = urlopen(url).read().decode("utf-8")
scraper = scrape_html(html,url)
scraper.nutrients()

{'calories': '970 calories', 'carbohydrateContent': '100 g', 'fatContent': '60 g', 'proteinContent': '12 g'}

...
url = "https://cookwell.com/recipe/lahmacun"
...
scraper.nutrients()

{'calories': '2558 calories', 'carbohydrateContent': '402 g', 'fatContent': '49 g', 'proteinContent': '132 g'}

Copy link
Collaborator

@jknndy jknndy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, this is a welcome improvement! I made a few small proposed changes for your review but looks great. Thanks!

recipe_scrapers/cookwell.py Outdated Show resolved Hide resolved
recipe_scrapers/cookwell.py Outdated Show resolved Hide resolved
recipe_scrapers/cookwell.py Outdated Show resolved Hide resolved
tests/test_data/cookwell.com/cookwell_1.json Outdated Show resolved Hide resolved
tests/test_data/cookwell.com/cookwell_2.json Outdated Show resolved Hide resolved
recipe_scrapers/cookwell.py Outdated Show resolved Hide resolved
eric-hoffmann and others added 2 commits January 7, 2025 21:24
Co-authored-by: Joey <7505194+jknndy@users.noreply.github.com>
@hhursev hhursev merged commit f77fbd3 into hhursev:main Jan 14, 2025
17 checks passed
@hhursev
Copy link
Owner

hhursev commented Jan 14, 2025

GTJ

@eric-hoffmann eric-hoffmann deleted the feature/cookwell-nutrition branch January 14, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants