Adapted code to get multiple results!

This commit is contained in:
Luke Rogers 2014-04-02 20:08:56 +13:00
parent 1062e69e56
commit c99c44616c
1 changed files with 6 additions and 3 deletions

View File

@ -52,13 +52,16 @@ def recipe(inp):
return "Could not get recipe: {}".format(e)
# find the list of results
results = search.find('div', {'class': 'found_results'})
result_list = search.find('div', {'class': 'found_results'})
if results:
result = results.find('div', {'class': 'recipe_result'})
if result_list:
results = result_list.find_all('div', {'class': 'recipe_result'})
else:
return "No results"
# pick a random front page result
result = random.choice(results)
# extract the URL from the result
url = BASE_URL + result.find('div', {'class': 'image-wrapper'}).find('a')['href']