Python-with-STP-Marketing-Strategy icon indicating copy to clipboard operation
Python-with-STP-Marketing-Strategy copied to clipboard

8-2 出現錯誤想請問如何解決~

Open chilun0908 opened this issue 3 years ago • 3 comments

使用方法

items_json = request_shopee(keyword = '運動內衣', page = 0)

items = {} #print(items_json) for i in range(len(items_json)): items[i] = items_json[i]['item_basic']

items

====>

TypeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_12424\4043242175.py in 5 #print(items_json) 6 for i in range(len(items_json)): ----> 7 items[i] = items_json[i]['item_basic'] 8 # items

TypeError: string indices must be integers

chilun0908 avatar Dec 22 '22 13:12 chilun0908

感謝回饋~ 目前正在解決中

WytheHuang avatar Dec 29 '22 07:12 WytheHuang

請問有新的進度嗎~目前8-2還是錯誤中! KeyError Traceback (most recent call last) in 1 # 使用方法 ----> 2 items_json = request_shopee(keyword = '衣服', page = 1) 3 4 items = {} 5 for i in range(len(items_json)):

in request_shopee(keyword, page) 8 getjson=json.loads(soup.text) 9 ---> 10 return getjson['items']

KeyError: 'items'

Hower84 avatar Jan 18 '23 01:01 Hower84

剛剛試 我也是遇到一樣情況KeyError: 'items' 是不是現在Shopee Open API v4是要跟shopee申請與註冊 ? 如果是 圖隊應該要重寫爬shopee商品頁的方式 而不是靠API 另外8-2是這本書STP最重要的開頭 這個fail 其他人根本沒法接下去學啦?

#專門用來請求蝦皮的相關商品基本資料
def request_shopee(keyword, page):
    url = 'https://shopee.tw/api/v4/search/search_items?by=relevancy&keyword=' + keyword + '&limit=60&newest=' + str(page*60) + '&order=desc&page_type=search&scenario=PAGE_GLOBAL_SEARCH&version=2'
    #開始請求

paulyang0125 avatar Nov 03 '23 05:11 paulyang0125