walmart.py should only consider "add to cart" if the item is actually on stock.
Actual Behaviour
On line 69 you have:
if "add to cart" in r.text.lower():
Depending on the item you look up, "r.text" contains a string "add to cart" even if the item is out of stock because the full string is:
<span>Why can’t I add to cart</span>
So, even if an item is out of stock, the condition is met and the script tries to add the item to the cart.
Expected Behavior
walmart.py should only consider "add to cart" if the item is actually on stock.
Actual Behaviour
On line 69 you have:
if "add to cart" in r.text.lower():
Depending on the item you look up, "r.text" contains a string "add to cart" even if the item is out of stock because the full string is:
<span>Why can’t I add to cart</span>
So, even if an item is out of stock, the condition is met and the script tries to add the item to the cart.
Repro Steps
Additional Context
Instead of this code
if "add to cart" in r.text.lower():
I was able to workaround using this because the capitalization is different:
if "Add to cart" in r.text:
The better alternative is to parse the response (r) for "itemprop="availability" and the response should be one of those:
So, adding something like this:
availability = doc.xpath('//link[@itemprop="availability"]/@href')[0]
with an appropriate condition might help...