繁体   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