I am struggling to get my head around this. If I scrape a value from a website for example a quantity number of a product, I will be running my python script until that quantity number will change and print the new quantity every time it changes.
Let's say the quantity is 50, if this goes to 51 or 49 my python script should print either increase or decrease. However this quantity '50' can't be predetermined as this value will keep changing. This is the part I am stuck on. I want it to keep running even if it increases/decreases to detect further changes. Right now I have this.
import requests
while True:
s = requests.Session()
req = s.get("url_here")
quantityval = re.compile('quant:([0-9])')
val = re.findall(quantityval,str(req.content))
#val output = '50'
quantity = (int(val))
if quantity != '50':
print ('Stock Change')
else:
print ('No Change, trying again...')
This will then only then use the '50' however I then want this 50 to be updated to the new number and so on.
last_quantity = 50followed bylast_quantity = quantitywhenever a change is witnessed?