I am trying to pull information on discounted products from this link. Currently, the results are being returned in a list using this code:
from selenium import webdriver #need to be able to quit out of the brower
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
opts = Options()
opts.headless=True
assert opts.headless # Operating in headless mode
browser = Firefox(options=opts)
browser.get(https://www.macys.com/shop/mens-clothing/mens-blazers-sports-coats/Productsperpage/120?id=16499)
html = browser.page_source
soup = BeautifulSoup(html,'html.parser')
discount = []
for tag in soup.find_all(class_='discount'):
discount.append(tag.text.strip())
print(discount)
browser.quit()
print('The program is terminated')
If a product isn't on sale, how could I return an element in the list like "N/A" or "Not on Sale"? Definitely will be some kind of if/else statement, but I'm not sure what the condition would be.
Any help is appreciated, thank you so much!