Creating a price tracker for Amazon at the moment and been running into a few problems, wondering if anyone can shed any light as to why I can't get this list to remove an element upon condition.
Here is what I am trying to make happen:
1.Check if in stock and price
If price below MAX, print Name, URL & Price
If found in stock and below MAX price, remove current URL and current MAX price from lists.
Continue checking other item(s) for prices below MAX.
As I am converting (Mapping) the first list to become Integers, I seem to be unable to use the .remove or any similar function to remove the MAX from list once the condition is met. (The URL is removed just fine)
Anyone able to point me in the right direction for this or explain how I can remove the MAX once product found?
Alternatively, does anyone know a way to sleep/ignore a list element for a certain or specific number of loop arounds once a condition has been met? This would be even more perfect.
Essentially, once condition is met, both elements at the current position in the looped lists should either be removed or slept for specific period of time
Thank you very much in advance if you're able to help or assist me to figure the answer out!
import requests
from bs4 import BeautifulSoup
MAXprices = ["80", "19"]
url_list = ["***AN EXAMPLE AMAZON LINK", "*****AN EXAMPLE AMAZON LINK********"]
while True:
MAXprice = map(int, MAXprices)
for (URL, MAX) in zip(url_list, MAXprice):
headers = {"User-Agent": ''}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
productName = soup.find(id="productTitle").get_text().strip()
productPrice = soup.find(class_="a-offscreen").get_text().strip()
converted_price = int(productPrice[1:3])
if converted_price < MAX:
print (productName)
print (URL)
print (productPrice)
url_list.remove(URL)
MAXprices.remove(MAX)
continue