diff --git a/finance_dl/amazon.py b/finance_dl/amazon.py index 3814da8..522109d 100644 --- a/finance_dl/amazon.py +++ b/finance_dl/amazon.py @@ -169,7 +169,8 @@ def invoice_finder(): order_ids = set() for invoice_link in invoices: - if "nvoice" not in invoice_link.text: + # Amazon Fresh, and regular orders respectively + if invoice_link.text not in ("View order", "View invoice"): continue href = invoice_link.get_attribute('href') m = re.match('.*[&?]orderID=((?:D)?[0-9\\-]+)(?:&.*)?$', href) @@ -264,8 +265,22 @@ def get_source(): source = self.driver.page_source if 'Grand Total:' in source: return source + if 'Final Details for Order' not in source: + return source return None + page_source, = self.wait_and_return(get_source) + if "Final Details for Order" not in page_source: + # every invoice has this phrase + logger.info(" Found possible Amazon Fresh order. Falling back to direct invoice URL.") + tokens = href.split("/") + tokens = tokens[:4] + tokens[-1] = f"gp/css/summary/print.html?orderID={order_id}" + href = "/".join(tokens) + logger.info(f"Looking for invoice at: {href}") + with self.wait_for_page_load(): + self.driver.get(href) + page_source, = self.wait_and_return(get_source) if order_id not in page_source: raise ValueError('Failed to retrieve information for order %r'