簡體   English   中英

我在使用 eBay python sdk 查找 API 時遇到問題

[英]I am having issues with the eBay python sdk finding API

我正在嘗試一個在智能設備上收集數據的項目。 我決定使用 eBay python SDK 而不是依賴網絡抓取。 我有幾個問題

  1. 當我請求特定項目(例如“iPhone x 64gb”)時,我會收到一個 eBay 列表的響應。 在列表中,一些列表項可能以a.) 的形式出現。iPhone 6 的列表,這不是我想要的。 b.) 兩部手機的列表(例如 iPhone x 64 Gb 和 256gb 版本)。 我如何過濾混亂?

  2. python SDK 的文檔是不夠的,因為我需要更多關於過濾 XML 響應以及向我的 API 請求添加搜索過濾器的教導。

  3. 我必須對同一項目進行多次調用,但對於響應將發送的另一個頁碼(最多 100 頁,每頁 100 個項目)。 我通常會看到很多相同商品、相同價格和 URL 指向同一個賣家的列表。 這可能無助於我對“iPhone x”的每日平均售價等指標進行准確的統計分析。 我如何從 API 獲得更好的樣本數據,因為我不會獲得所有“iPhone X”列表?

所有的問題都是在使用查找API時遇到的。

from ebaysdk.finding import Connection as find_connect
from statistics import mean, median
from bs4 import BeautifulSoup

APP_ID = 'Removed for privacy reasons'
# keywords = input("Enter search keywords(e.g 'white board'): ")

api = find_connect(appid=APP_ID, config_file=None,  siteid="EBAY-ENCA")
request = {
        'keywords': "Iphone x 64gb",
        'itemFilter': [
            {'name': 'Condition', 'value': 'Used'},
            {'name': 'currency', 'value': 'CAD'},
            {'name': 'minPrice', 'value': 100.0}
        ],
        'paginationInput': {
            'entriesPerPage': 100,
            'pageNumber': 1
        },
    }
response = api.execute('findItemsByKeywords', request)

# print(responses.dict())
soup = BeautifulSoup(response.content, 'lxml')
totalentries = int(soup.find('totalentries').text)
items = soup.find_all('item')

print(f"{totalentries} items found")

print_no = 0
prices = []
print(f"Current list is {len(items)} items long")
for item in items:
    cat = item.categoryname.string.lower()
    title = item.title.string.lower()
    price = int(round(float(item.currentprice.string)))
    url = item.viewitemurl.string.lower()

    print('-'*20)
    print(f"{cat}\n{title}\n{price}\n{url}\n")
    prices.append(price)
    print_no += 1

print(f"{print_no} items have been printed")
print(f"Average price is ${mean(prices)}. Median is ${median(prices)}")

我可以收到輸出,例如

3242 items found
Current list is 100 items long

--------------------
# The problem about two different phones in one listing that I was talking about
cell phones & smartphones
apple iphone x silver & gray gsm unlocked 64gb or 256gb
600
https://www.ebay.ca/itm/apple-iphone-x-silver-gray-gsm-unlocked-64gb-256gb-/273580927268?var=572990606496

--------------------
# Basically a duplicate of the above listing
cell phones & smartphones
apple iphone x silver & gray gsm unlocked 64gb or 256gb
600
https://www.ebay.ca/itm/apple-iphone-x-silver-gray-gsm-unlocked-64gb-256gb-/273580927268?var=572990606496

--------------------
# I did not search for an iPhone 8
mobile phones
apple iphone 8 - 64gb - silver (unlocked) model a1863 
152
https://www.ebay.ca/itm/apple-iphone-8-64gb-silver-unlocked-model-a1863-/174235235608

--------------------
# This is what I wanted
cell phones & smartphones
apple iphone x 64gb silver unlocked 5.8 in ios smartphone-visible shadow/burn-in
460
https://www.ebay.ca/itm/apple-iphone-x-64gb-silver-unlocked-5-8-ios-smartphone-visible-shadow-burn-in-/174212340572?var=473126790373

--------------------
# X not Xs max
mobile phones
apple iphone xs max [64gb / 256gb /512gb] cheap unlocked [au stock] free express
1019
https://www.ebay.ca/itm/apple-iphone-xs-max-64gb-256gb-512gb-cheap-unlocked-au-stock-free-express-/324024310348?var=513068412663

100 items have been printed # removed most listings from output for brevity
Average price is $566.2. Median is $600

事實上,我幾個月前就完成了非常相似的項目(對於移動公司,定價的統計分析也是如此)。 這是我實現的簡短而簡單的存儲庫: https : //github.com/Brat-Pit/eBay

我的一般方法:使用findItemsAdvanced()獲取項目的 ID 列表,然后使用GetMultipleItems()獲取其他數據。

但是,回到你的問題:

Ad.1如果您想以某種方式過濾商品,請首先獲取商品的 ID 列表(例如,在findItemsAdvanced() 中使用價格/描述過濾器)。 然后使用ebaysdk.shopping和方法GetMultipleItems() 您將可以訪問項目的屬性(如 RAM 內存、屏幕大小等)

Ad.2確實如此。 我從論壇獲取的信息中約有 80%,通過文檔獲取的信息占 20%。

Ad.3我明白你的意思。 每日限制為 5000 次查詢。 我的解決方案是首先使用findItemsAdvanced()按相關性對數據進行排序(根據單個指定的排序順序對返回的項目進行排序。默認值:BestMatch。所以你不需要做任何類似排序的事情)然后只下載最“流行的” ' 拍賣(用戶選擇/購買它們並非沒有原因,這是幕后的主要思想)。

希望能幫助到你。

您可以按方面而不是關鍵字查詢。 這應該會返回更多的預期結果。

api_request = {
    'keywords': "Iphone x",
    'itemFilter': [
        {'name': 'Condition', 'value': 'Used'},
        {'name': 'currency', 'value': 'CAD'},
        {'name': 'minPrice', 'value': 100.0}
    ],
    'aspectFilter': [
        {
            'aspectName': 'Storage Capacity',
            'aspectValueName': '16 GB',
        }
    ],
    'categoryId': 9355,
    'outputSelector': [
        'AspectHistogram',
    ],
    'paginationInput': {
        'entriesPerPage': 100,
        'pageNumber': 1
    },
    'sortOrder': 'BestMatch'
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM