Thank you for your time!
Each products, sometimes have more than one model. I got the model ‘name’ and ‘price’ of the respective models within a single product via a for loop.
But, how do I ‘transfer’ these details to the ‘yield’ section along with other variables of that same product? Below is my attempt, but i am not getting it correct. How do I edit the code, so that, it could record more than one models (along with the price) within a same product, wherever applicable:
JavaScript
x
17
17
1
for i in resp['item']['models']:
2
if i['name'] is not None:
3
model = i['name']
4
model_pricing = i['price']
5
6
7
yield{
8
'product': resp.get('item').get('name'),
9
'rating': resp.get('item').get('item_rating').get('rating_star'),
10
'review numbers': resp.get('item').get('cmt_count'),
11
'viewcount': resp.get('item').get('view_count'),
12
'likes': resp.get('item').get('liked_count'),
13
'model_pricing': model_pricing,
14
'model': model,
15
'location': resp.get('item').get('shop_location')
16
}
17
Advertisement
Answer
You should keep your yield inside for loop and if statement. You can try as follows:
JavaScript
1
16
16
1
for i in resp['item']['models']:
2
if i['name'] is not None:
3
model = i['name']
4
model_pricing = i['price']
5
6
yield {
7
'product': resp.get('item').get('name'),
8
'rating': resp.get('item').get('item_rating').get('rating_star'),
9
'review numbers': resp.get('item').get('cmt_count'),
10
'viewcount': resp.get('item').get('view_count'),
11
'likes': resp.get('item').get('liked_count'),
12
'model_pricing': model_pricing,
13
'model': model,
14
'location': resp.get('item').get('shop_location')
15
}
16