| |
| """20240808_新MOMO.ipynb |
| Automatically generated by Colab. |
| Original file is located at |
| https://colab.research.google.com/drive/1ESDWd6QhT5vweJgAzoo2bVPByT4ioFt2 |
| """ |
| import requests |
| import pandas as pd |
| import streamlit as st |
|
|
| st.title("MOMO商品搜索") |
|
|
| |
| keyword = st.text_input("請輸入搜索關鍵字", "羽球鞋") |
| page_num = st.number_input("請輸入頁數", min_value=1, step=1) |
|
|
| 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_num), |
| "priceS": "0", |
| "priceE": "9999999", |
| "searchType": "1", |
| "reduceKeyword": "", |
| "isFuzzy": "0", |
| "rtnCateDatainfo": { |
| "cateCode": "", |
| "cateLv": "-1", |
| "keyword": keyword, |
| "curPage": str(page_num), |
| "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}) |
| df = pd.DataFrame(product_list) |
| st.dataframe(df) |
| else: |
| st.write(f"請求失敗,狀態碼: {response.status_code}") |