producer-raw-recipies_4.py 730 B

12345678910111213141516171819202122232425
  1. def get_recipes():
  2. recipies = []
  3. salad_url = 'https://www.allrecipes.com/recipes/96/salad/'
  4. url = 'https://www.allrecipes.com/recipes/96/salad/'
  5. print('Accessing list')
  6. try:
  7. r = requests.get(url, headers=headers)
  8. if r.status_code == 200:
  9. html = r.text
  10. soup = BeautifulSoup(html, 'lxml')
  11. links = soup.select('.fixed-recipe-card__h3 a')
  12. idx = 0
  13. for link in links:
  14. sleep(2)
  15. recipe = fetch_raw(link['href'])
  16. recipies.append(recipe)
  17. idx += 1
  18. except Exception as ex:
  19. print('Exception in get_recipes')
  20. print(str(ex))
  21. finally:
  22. return recipies