Advertisement
gregwa

FCM154 - scrapertest.py

Feb 6th, 2020
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. from recipe_scrapers import scrape_me, SCRAPERS
  2. from urllib.parse import urlparse
  3.  
  4. # site = 'https://www.allrecipes.com/recipe/61024/asian-orange-chicken/'
  5.  
  6. site = input('Please enter the website URL to scrape (blank line to quit) ->')
  7.  
  8. if site != '':
  9.     # Now check to see if the domain is in the SCRAPERS dictionary...
  10.     domain = urlparse(site).netloc
  11.     domain = domain.replace("www.", "")
  12.     if domain in SCRAPERS:
  13.         scraper = scrape_me(site)
  14.         title = scraper.title()
  15.         total_time = scraper.total_time()
  16.         yields = scraper.yields()
  17.         ingredients = scraper.ingredients()
  18.         instructions = scraper.instructions()
  19.         image = scraper.image()
  20.        
  21.         print(f'Title: {title}')
  22.         print(f'Total Time: {total_time}')
  23.         print(f'Servings: {yields}')
  24.         # print(f'Ingredients: {ingredients}')
  25.         print('Ingredients:\n')
  26.         for ing in ingredients:
  27.             print(f'    {ing}')
  28.         print(f'\nInstructions: {instructions}')
  29.         print(f'Image URL: {image}')
  30.     else:
  31.         print('\nSorry, that website is not currently supported.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement