Spaces:
Sleeping
Sleeping
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() |