Added integration for finding cooking recipes

This commit is contained in:
2021-09-04 21:53:55 +02:00
parent 63c64f389d
commit 3112feadab
2 changed files with 33 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
*.ini *.ini
*.html

32
cooking_recipe_finder.py Normal file
View File

@@ -0,0 +1,32 @@
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
options = Options()
options.headless = True
options.add_argument("--window-size=1920,1200")
driver = webdriver.Chrome(options=options, executable_path=r'/usr/local/bin/chromedriver')
driver.get("https://restegourmet.de/rezeptsuche/muss_hauptspeisen/,rocula,gnocchi,tomaten/direkt-loslegen")
timeout = 5
try:
element_present = EC.presence_of_all_elements_located((By.CLASS_NAME, 'source-url'))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print("Timed out waiting for page to load")
with open("source.html", 'w') as f:
f.write(driver.page_source)
links = driver.find_elements_by_class_name("source-url")
for link in links:
print(link.text)
# links_cleaned = [link.text.replace("Quelle: ", "") for link in links]
# print(links_cleaned)
driver.quit()