我正在尝试在 Opensea.io 上获取收藏 Aethir Wars 的所有者列表。我想要所有者、他们持有的 NFT 以及他们的 ETH 地址。我能够获得一长串所有者及其地址,但由于某种原因,该列表并不完整。此外,我必须添加一个 if 语句,因为如果 NFT 已转移但未购买,则“Last_Sale”参数为空。任何帮助表示赞赏。
import requests
url = "https://api.opensea.io/api/v1/assets"
api_key = "api key"
col = 'reapers'
def print_owners(race, offset):
querystring = {'order_by': 'name', 'order_direction': 'asc', 'offset': offset, 'limit': '50',
'collection': col, 'X-API-KEY': api_key}
response = requests.get(url, params=querystring)
data = response.json()
i = 0
for each_asset in data['assets']:
try:
if race in data['assets'][0]['name']:
if data["assets"][i]["last_sale"] is None:
print(data["assets"][i]["name"] + ': '
+ data["assets"][i]["sell_orders"][0]["maker"]["address"])
else:
print(data["assets"][i]["name"] + ': '
+ data["assets"][i]["last_sale"]["transaction"]["from_account"]["user"]["username"])
except TypeError:
pass
i += 1
x = range(0, 600, 50)
for stuff in x:
try:
print_owners(race='Reaper', offset=str(stuff))
except KeyError:
pass
try:
print_owners(race='Android', offset=str(stuff))
except KeyError:
pass
try:
print_owners(race='Goblin', offset=str(stuff))
except KeyError:
pass