我是python新手,事实上,这是我的第一个python项目。我使用ebaysdk搜索ebay上的电子产品,我希望它返回多个结果,因为我的应用程序是比较价格,但它只返回一个结果。你知道吗
有人请帮助我使代码返回多个结果。你知道吗
这是我的代码片段。你知道吗
@app.route('/ebay_page_post', methods=['GET', 'POST'])
def ebay_page_post():
if request.method == 'POST':
#Get json format of the text sent by Ajax
search = request.json['search']
try:
#ebaysdk code starts here
api = finding(appid='JohnOkek-hybridse-PRD-5c2330105-9bbb62f2', config_file = None)
api_request = {'keywords':search, 'outputSelector': 'SellerInfo', 'categoryId': '293'}
response = api.execute('findItemsAdvanced', api_request)
soup = BeautifulSoup(response.content, 'lxml')
totalentries = int(soup.find('totalentries').text)
items = soup.find_all('item')
for item in items:
cat = item.categoryname.string.lower()
title = item.title.string.lower().strip()
price = int(round(float(item.currentprice.string)))
url = item.viewitemurl.string.lower()
seller = item.sellerusername.text.lower()
listingtype = item.listingtype.string.lower()
condition = item.conditiondisplayname.string.lower()
print ('____________________________________________________________')
#return json format of the result for Ajax processing
return jsonify(cat + '|' + title + '|' + str(price) + '|' + url + '|' + seller + '|' + listingtype + '|' + condition)
except ConnectionError as e:
return jsonify(e)
根据您提供的代码,添加了可以使用的键值对集合示例:
我能解决这个问题。你知道吗
Click here to see how i did it
感谢每一位贡献者,我非常感谢你们。你知道吗
找到第一个项目后,将其添加到集合中。在for循环完成后,返回集合。你知道吗
现在,一旦找到第一个,就返回(中断迭代)
相关问题 更多 >
编程相关推荐