MOMO_streamlit / app.py
Roberta2024's picture
Update app.py
cc8429f verified
import requests
import pandas as pd
import streamlit as st
def search_momoshop(keyword, page_number):
url = "https://apisearch.momoshop.com.tw/momoSearchCloud/moec/textSearch"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
}
payload = {
"host": "momoshop",
"flag": "searchEngine",
"data": {
"specialGoodsType": "",
"isBrandSeriesPage": "false",
"authorNo": "",
"originalCateCode": "",
"cateType": "",
"searchValue": keyword,
"cateCode": "",
"cateLevel": "-1",
"cp": "N",
"NAM": "N",
"first": "N",
"freeze": "N",
"superstore": "N",
"tvshop": "N",
"china": "N",
"tomorrow": "N",
"stockYN": "N",
"prefere": "N",
"threeHours": "N",
"video": "N",
"cycle": "N",
"cod": "N",
"superstorePay": "N",
"showType": "chessboardType",
"curPage": str(page_number),
"priceS": "0",
"priceE": "9999999",
"searchType": "1",
"reduceKeyword": "",
"isFuzzy": "0",
"rtnCateDatainfo": {
"cateCode": "",
"cateLv": "-1",
"keyword": keyword,
"curPage": str(page_number),
"historyDoPush": "false",
"timestamp": 1723036027826
},
"flag": 2018,
"serviceCode": "MT01",
"addressSearchData": {},
"adSource": "tenmax"
}
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
data = response.json()
products = data.get('rtnSearchData', {}).get('goodsInfoList', [])
product_list = []
for product in products:
name = product.get('goodsName', '')
price = product.get('goodsPrice', '')
product_list.append({'品名': name, '價格': price})
return pd.DataFrame(product_list)
else:
st.error(f"請求失敗,狀態碼: {response.status_code}")
return None
# Streamlit App
st.title("MomoShop 商品搜尋")
keyword = st.text_input("請輸入搜尋關鍵字:", "羽球鞋")
page_number = st.number_input("請輸入頁數:", min_value=1, value=1)
if st.button("搜尋"):
result_df = search_momoshop(keyword, page_number)
if result_df is not None:
st.dataframe(result_df)