Closed obsidian33 closed 1 year ago
If anyone stumbles across this. I found that the item it was finding was one of my saved meals. If you have saved meals you'll get the above error as the HTML document doesn't have a paragraph element with the class='search-nutritional-info'.
I updated my local copy of the source code to skip items where the anchor element has an attribute of 'data-food-type'='1'. Once I've ironed out all my use cases I will perform a pull request on this repo.
Here is the updated code in client.py:
def _get_food_search_results(self, document) -> List[FoodItem]:
item_divs = document.xpath("//li[@class='matched-food']")
items = []
for item_div in item_divs:
# get mfp info from search results
a = item_div.xpath(".//div[@class='search-title-container']/a")[0]
# if it is a meal, skip it
if a.get("data-food-type") == '1': continue
@obsidian33 is it the right thing to do to skip these entries? I think it would be nice to include them. These items don't seem to have a tag with class search-nutritional-info
, so we could just leave nutrition info blank for these items (that seems to be what the website does too).
I was trying to search for a specific type of food and received this error:
Searching using this string in the browser does seem to work:
If I slowly add words to the search string I can find it with just "timber wolf" but as soon as I try "timber wolf keto" I get the exception (I shortened the results):