我在eBay python sdk查找API中遇到问题

问题描述 投票:0回答:1

我正在尝试一个在智能设备上收集数据的项目。我决定使用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

我正在尝试一个在智能设备上收集数据的项目。我决定使用eBay python SDK,而不是依赖于网络抓取。当我请求...

python ebay-api ebay-sdk
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.