我正在尝试一个在智能设备上收集数据的项目。我决定使用 eBay python SDK 而不是依赖网络抓取。我有几个问题
当我对特定项目(例如“iPhone x 64gb”)提出请求时,我收到一个响应,即 eBay 列表。在列表中,一些列表项可能以 a.) iPhone 6 的列表形式出现,这不是我想要的。b.) 两部手机的列表(例如 iPhone x 64 Gb 和 256gb 版本)。我如何过滤混乱?
python SDK 的文档不足,因为我需要更多关于过滤 XML 响应以及将搜索过滤器添加到我的 API 请求的教学。
我必须对同一项目进行多次调用,但要为响应将发送的另一个页码(最多 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