import requests import json from dotenv import load_dotenv import os load_dotenv() username = os.environ.get('USERNAME') passwd = os.environ.get('PASSWORD') def scrape_amazon(search_query, n =10): # 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