返回多个项目 [英] Return multiple items

查看:91
本文介绍了返回多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实上,我是python的新手,这是我的第一个python项目。我正在使用ebaysdk在ebay上搜索电子产品,我希望它返回多个结果,因为我的应用程序用于比较价格,但它只返回一个结果。

i am new to python as a matter of fact, this is my first python project. I am using ebaysdk to search for electronics on ebay and i want it to return multiple results because my app is for comparing prices but it returns only one result.

请有人帮忙我让代码返回多个结果。

Someone please help me to make the code return multiple results.

这是我的代码段。

@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)


推荐答案

我能够解决问题。

点击此处查看我的操作方式

感谢大家贡献者,我最感谢大家。

Thanks to every contributor, i am most grateful to you all.

这篇关于返回多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆