Spaces:
Sleeping
Sleeping
File size: 3,372 Bytes
39a482a bc9c183 39a482a 6d0cb99 39a482a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
from scraper_tiki import *
from scraper_lazada import *
from scraper_shopee import *
import pandas as pd
import streamlit as st
# #test Tiki
# start_driver()
# DRIVER.get('https://tiki.vn/search?sort=price%2Casc&q=megaduo')
# time.sleep(3)
# products = DRIVER.find_elements(By.CLASS_NAME, 'product-item')
# product = products[2]
# info = get_tiki_product_info_single(product, True)
# print(info)
# # Test Lazada
# start_driver()
# DRIVER.get('https://www.lazada.vn/catalog/?page=1&q=megaduo&sort=priceasc')
# time.sleep(3)
# products = DRIVER.find_elements(By.CLASS_NAME, 'Bm3ON')
# product = products[2]
# info = get_lazada_product_info_single(product, True)
# print(info)
def main():
st.title("Price Comparison (So Sánh Giá)")
with st.form(key="user_input_form"):
search_product = st.text_input("What would you like to buy? (Bạn muốn mua gì?)")
submit_button = st.form_submit_button(label="Search")
if submit_button:
print('Scraping', search_product)
# search_product = "megaduo"
# search_product = input("Search for what? ")
num_max_page = 1
extra_info = True
n_products_to_view = 5 # Change this as you like to check more products
col_to_display = ['name', 'price', 'product_url', 'image']
st.subheader("Shopee")
shopee_data = scrap_shopee(search_product, num_max_page, extra_info)
if shopee_data:
df_shopee = pd.DataFrame(data=shopee_data, columns=shopee_data[0].keys())
print(df_shopee.head())
st.write(df_shopee[col_to_display].sort_values(by='price').head(n_products_to_view))
else:
df_shopee = pd.DataFrame(columns = col_to_display)
st.write("Not found.")
st.subheader("Lazada")
lazada_data = scrap_lazada(search_product, num_max_page, extra_info)
if lazada_data:
df_lazada = pd.DataFrame(data=lazada_data, columns=lazada_data[0].keys())
print(df_lazada.head())
st.write(df_lazada[col_to_display].sort_values(by='price').head(n_products_to_view))
else:
df_lazada = pd.DataFrame(columns = col_to_display)
st.write("Not found.")
st.subheader("Tiki")
tiki_data = scrap_tiki(search_product, num_max_page, extra_info)
if tiki_data:
df_tiki = pd.DataFrame(data=tiki_data, columns=tiki_data[0].keys())
print(df_tiki.head())
st.write(df_tiki[col_to_display].sort_values(by='price').head(n_products_to_view))
else:
df_tiki = pd.DataFrame(columns = col_to_display)
st.write("Not found.")
# Merge the two dataframes
# merged_df = pd.concat([df_tiki, df_lazada, df_shopee])
merged_df = pd.concat([df_lazada])
# Sort the merged dataframe by price
sorted_merged_df = merged_df.sort_values(by='price')
print(sorted_merged_df.head(n_products_to_view))
st.subheader("All sites, sorted by price ascending (Sắp xếp theo giá tăng dần)")
st.write(sorted_merged_df.head(n_products_to_view))
if __name__ == "__main__":
main() |