简体   繁体   English

我在使用 eBay python sdk 查找 API 时遇到问题

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

I am trying to work on a project which collects data on smart devices.我正在尝试一个在智能设备上收集数据的项目。 I have decided to use the eBay python SDK rather than rely on web scraping.我决定使用 eBay python SDK 而不是依赖网络抓取。 I am having a few issues我有几个问题

  1. When I make a request for a particular Item for example "iPhone x 64gb", I get a response which is a list of eBay listings.当我请求特定项目(例如“iPhone x 64gb”)时,我会收到一个 eBay 列表的响应。 Among the listings, some of the listing items may come in the form of a.) A listing of an iPhone 6 which is not what I wanted.在列表中,一些列表项可能以a.) 的形式出现。iPhone 6 的列表,这不是我想要的。 b.) A listing of two phones (eg an iPhone x 64 Gb and 256gb versions). b.) 两部手机的列表(例如 iPhone x 64 Gb 和 256gb 版本)。 How do I filter through the mess?我如何过滤混乱?

  2. The documentation for the python SDK is insufficient as I need more teachings on filtering the XML responses and also adding search filters to my API request. python SDK 的文档是不够的,因为我需要更多关于过滤 XML 响应以及向我的 API 请求添加搜索过滤器的教导。

  3. I have to make multiple calls for the same item but for another page number that the response will send (max is 100 pages with 100 items per page).我必须对同一项目进行多次调用,但对于响应将发送的另一个页码(最多 100 页,每页 100 个项目)。 I usually see a lot of listings of the same item, the same price and their URLs point to the same seller.我通常会看到很多相同商品、相同价格和 URL 指向同一个卖家的列表。 This probably won't help me make an accurate statistical analysis on metrics such as the daily average sale price of "iPhone x".这可能无助于我对“iPhone x”的每日平均售价等指标进行准确的统计分析。 How do I get a better sample data from the API as I won't be given all the "iPhone X" listings?我如何从 API 获得更好的样本数据,因为我不会获得所有“iPhone X”列表?

All the problems are encountered when using the finding API.所有的问题都是在使用查找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)}")

I can receive an output such as我可以收到输出,例如

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

As a matter of fact, I have finished very similar project few months ago (for mobile company, pricings' statistical analysis as well).事实上,我几个月前就完成了非常相似的项目(对于移动公司,定价的统计分析也是如此)。 Here is my short and simple to implement repository: https://github.com/Brat-Pit/eBay这是我实现的简短而简单的存储库: https : //github.com/Brat-Pit/eBay

My general approach: get items' ID list using findItemsAdvanced() , then use GetMultipleItems() to get additional data.我的一般方法:使用findItemsAdvanced()获取项目的 ID 列表,然后使用GetMultipleItems()获取其他数据。

But, back to Your questions:但是,回到你的问题:

Ad.1 If You want to somehow filter items, first get items' ID list (using price/description filters in findItemsAdvanced() for example). Ad.1如果您想以某种方式过滤商品,请首先获取商品的 ID 列表(例如,在findItemsAdvanced() 中使用价格/描述过滤器)。 Then use ebaysdk.shopping and method GetMultipleItems() .然后使用ebaysdk.shopping和方法GetMultipleItems() You'll get access into item's attributes (like RAM memory, screen size, etc.)您将可以访问项目的属性(如 RAM 内存、屏幕大小等)

Ad.2 That's true. Ad.2确实如此。 About 80% of information I acquired from forums, 20% via documentation.我从论坛获取的信息中约有 80%,通过文档获取的信息占 20%。

Ad.3 I understand Your point. Ad.3我明白你的意思。 Daily limit is 5000 queries.每日限制为 5000 次查询。 My solution was to order the data by relevance first using findItemsAdvanced() (sort the returned items according to a single specified sort order. Default: BestMatch. So You dont't need to do anything like sort) and then download only most 'popular' auctions (users are picking/buying them not without the reason and that's the main idea behind the scenes).我的解决方案是首先使用findItemsAdvanced()按相关性对数据进行排序(根据单个指定的排序顺序对返回的项目进行排序。默认值:BestMatch。所以你不需要做任何类似排序的事情)然后只下载最“流行的” ' 拍卖(用户选择/购买它们并非没有原因,这是幕后的主要思想)。

Hope it helps.希望能帮助到你。

You could query by aspect instead of keyword.您可以按方面而不是关键字查询。 This should return more expected results.这应该会返回更多的预期结果。

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