File size: 2,432 Bytes
e945ba8
 
 
 
 
 
 
 
fb756b6
 
 
 
 
 
 
e945ba8
 
 
 
 
 
 
 
 
 
 
 
 
 
fb756b6
e945ba8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb756b6
e945ba8
 
 
 
 
 
 
 
fb756b6
 
e945ba8
 
 
 
 
 
 
 
fb756b6
 
 
 
 
 
 
 
 
 
 
 
e945ba8
fb756b6
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
# -*- coding: utf-8 -*-
"""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}")