naufalnashif commited on
Commit
a1b9884
·
1 Parent(s): 90310fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -32,10 +32,25 @@ def scrape_e_commerce(nama_barang, num_items):
32
  if '/product/' in product_href:
33
  product_name = product.find('div', class_='title').text.strip()
34
  product_price = product.find('span', class_='normal price-value').text.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  product_link = f"https://www.klikindomaret.com{product_href}"
36
  products.append({
37
  'product': product_name,
38
  'price': product_price,
 
 
39
  'link': product_link
40
  })
41
 
 
32
  if '/product/' in product_href:
33
  product_name = product.find('div', class_='title').text.strip()
34
  product_price = product.find('span', class_='normal price-value').text.strip()
35
+
36
+ # Cek apakah ada harga sebelum diskon dan persentase diskon
37
+ discount_element = product.find('span', class_='strikeout disc-price')
38
+ discount_percentage = ""
39
+ original_price = ""
40
+ if discount_element:
41
+ discount_percentage = discount_element.find('span', class_='discount').text.strip()
42
+ original_price = discount_element.text.replace(discount_percentage, '').strip()
43
+ else:
44
+ # Jika tidak ada diskon, set discount_percentage ke "0%" dan original_price ke product_price
45
+ discount_percentage = "0%"
46
+ original_price = product_price
47
+
48
  product_link = f"https://www.klikindomaret.com{product_href}"
49
  products.append({
50
  'product': product_name,
51
  'price': product_price,
52
+ 'original_price': original_price,
53
+ 'discount_percentage': discount_percentage,
54
  'link': product_link
55
  })
56