为了账号安全,请及时绑定邮箱和手机立即绑定

返回多个项目

返回多个项目

哔哔one 2021-08-05 10:18:53
事实上,我是 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)
查看完整描述

3 回答

?
慕尼黑的夜晚无繁华

TA贡献1864条经验 获得超6个赞

找到第一个项目后,将其添加到集合中。在 for 循环完成后,返回集合。

现在,一旦您找到第一个,您就会返回(打破迭代)


查看完整回答
反对 回复 2021-08-05
  • 3 回答
  • 0 关注
  • 102 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号