Here’s a quick example of using the AI web scraper to extract information from an Amazon product page:
Copy
from jigsawstack import JigsawStack# Initialize the SDKjigsawstack = JigsawStack() # API key from environment variables# Define parameters for web scrapingparams = { "url": "https://www.amazon.com/Cadbury-Mini-Caramel-Eggs-Bulk/dp/B0CWM99G5W", "element_prompts": ["prices", "title", "ratings", "product_details"]}# Make the API callresult = jigsawstack.web.ai_scrape(params)# Print the resultsprint(f"Product Title: {result.get('title')}")print(f"Price Information: {result.get('prices')}")
JigsawStack returns structured data as Python dictionaries. Here’s how to handle the response:
Copy
# Example response handlingtry: result = jigsawstack.web.ai_scrape(params) # Access nested data if "prices" in result: current_price = result["prices"].get("current_price") print(f"Current Price: ${current_price}") # Iterate through multiple results if "product_details" in result: print("Product Details:") for key, value in result["product_details"].items(): print(f"- {key}: {value}")except Exception as e: print(f"Error: {e}")
sentiment_result = jigsawstack.ai.sentiment({ "text": "I absolutely love this product! It's amazing!"})print(f"Sentiment: {sentiment_result.get('sentiment')}")print(f"Score: {sentiment_result.get('score')}")
speech = jigsawstack.audio.text_to_speech({ "text": "Welcome to JigsawStack Python SDK!", "voice": "en-US-female"})# Save the audio to a filewith open("welcome_message.mp3", "wb") as audio_file: audio_file.write(speech.content)