I am scraping a supermarket
(https://www.sklavenitis.gr/eidi-artozacharoplasteioy/psomi-typopoiimeno/)
I have the urls on a file and read them and iterate through them.
But the selenium is confused about some elements which are not existing e.g.
on the second link which is on sale the price is correct but afterwards like the third or fourth link which are not in discount it still prints the value of the second link and again when something is in discount all is okay, but if is not in discount get the previous discounted value. Should I close my driver in every iteration and reopen it? I saw some posts and they didn't do that for that I am asking
options = webdriver.ChromeOptions()
delay = 10
options.add_argument(f'user-agent={user_agent}')
options.add_argument("start-maximized")
options.add_argument('--no-sandbox')
options.add_argument('--disable-infobars')
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s, options=options)
for link in links:
driver.get(link)
myElem =WebDriverWait(theDriver,
delay).until(EC.presence_of_element_located((By.XPATH, "//h1[@class='product-
detail__title']")))
driver.find_element(by=By.XPATH, value="//div[@class='product-detail__left']").find_element(by=By.XPATH, value="//div[@class='deleted__price']").text.replace(",", ".")
Edit#1 Sorry for the confusion I want to scrape the prices before the discount and after the discount.( If there is not a discount it just print the current price). My problem is on the items which are not in discount, selenium shows that somehow there is a discounts for that reason I added the class product detail left to be more strict about scraping but it didn't work.