Adapted code to get multiple results!
This commit is contained in:
parent
1062e69e56
commit
c99c44616c
|
@ -52,13 +52,16 @@ def recipe(inp):
|
||||||
return "Could not get recipe: {}".format(e)
|
return "Could not get recipe: {}".format(e)
|
||||||
|
|
||||||
# find the list of results
|
# find the list of results
|
||||||
results = search.find('div', {'class': 'found_results'})
|
result_list = search.find('div', {'class': 'found_results'})
|
||||||
|
|
||||||
if results:
|
if result_list:
|
||||||
result = results.find('div', {'class': 'recipe_result'})
|
results = result_list.find_all('div', {'class': 'recipe_result'})
|
||||||
else:
|
else:
|
||||||
return "No results"
|
return "No results"
|
||||||
|
|
||||||
|
# pick a random front page result
|
||||||
|
result = random.choice(results)
|
||||||
|
|
||||||
# extract the URL from the result
|
# extract the URL from the result
|
||||||
url = BASE_URL + result.find('div', {'class': 'image-wrapper'}).find('a')['href']
|
url = BASE_URL + result.find('div', {'class': 'image-wrapper'}).find('a')['href']
|
||||||
|
|
||||||
|
|
Reference in New Issue