import requests import json import os username = os.environ.get('USERNAME') passwd = os.environ.get('PASSWORD') def scrape_amazon(search_query, n =20): # Structure payload. payload = { 'source': 'amazon_search', 'domain': 'com', 'query': f'{search_query}', 'start_page': 1, 'pages': 1, 'parse': True, # 'context': [ # {'key': 'category_id', 'value': 16391693031} # ], } # Get response. response = requests.request( 'POST', 'https://realtime.oxylabs.io/v1/queries', auth=(username, passwd), json=payload, ) result = json.loads(response.content) final_result = {} i=0 # Parse result. for item in result['results'][0]['content']['results']['organic']: if i