Below is a single HTML page that creates a search tool to fetch Amazon's top-selling products with their review data (e.g., top reviews, ratings) using a simulated approach, as direct Amazon API access requires credentials and their Product Advertising API has limitations for real-time scraping. Instead, this example uses a mock dataset to demonstrate the functionality, displaying 5 to 50 top-selling products with review details and providing an Excel download option within the same page.
For real-world use, you’d need to integrate Amazon’s Product Advertising API (PA-API) or a third-party service, which requires an API key and compliance with Amazon’s terms. Since I can’t access real-time Amazon data directly, this solution simulates the process and includes an Excel export feature using the SheetJS library.
### HTML Page:
```html
Amazon Top Products Review Search Tool
```
### Features:
1. **User Interface:**
- Input field for category (e.g., "Electronics", "Books")
- Dropdown to select number of products (5, 10, 25, 50)
- Search button to fetch results
- Download button for Excel export
- Progress bar for simulated loading
- Table to display results
2. **Functionality:**
- **Search Tool:** Users enter a category and select a product limit (5–50).
- **Result Display:** Shows a table with:
- Rank
- Product Name
- Rating (out of 5)
- Review Count
- Top Review (sample text)
- **Excel Export:** Downloads results in Excel format using SheetJS.
3. **Simulation:**
- Uses a `mockData` object with sample top-selling products and review data (e.g., Electronics, Books).
- Simulates API delay with a progress bar.
### How to Use:
1. Save this code as an HTML file (e.g., `amazon_review_search.html`).
2. Open it in a web browser.
3. Enter a category (e.g., "Electronics" or "Books") and select a limit (5, 10, 25, or 50).
4. Click "Search Products" to see the table of top-selling products with review data.
5. Click "Download Excel" to export the results as an Excel file (`Amazon_Top_Products.xlsx`).
### Notes for Production:
- **Real API Integration:**
- Replace `mockData` with Amazon’s Product Advertising API (PA-API). You’d need:
- An Amazon Associate account.
- API credentials (Access Key, Secret Key, Associate Tag).
- A request like: `https://webservices.amazon.com/paapi5/searchitems` with parameters for category and best-seller filtering.
- PA-API returns ASINs, titles, ratings, and review counts, but top review text might require scraping (against Amazon’s terms) or a separate review API.
- **Limitations:**
- The mock data here is limited to a few entries. For 50 products, you’d need to expand the dataset or fetch real data.
- Amazon’s API has rate limits (e.g., 1 request/second per Associate account), so you’d need to handle throttling.
- **Photos:** This version omits photos as PA-API doesn’t provide top review text or images directly. For images, use the `Images.Primary.Medium.URL` field from PA-API responses.
- **Legal Note:** Scraping Amazon directly (outside PA-API) violates their terms of service. Use official APIs or third-party services like Rainforest API (paid) for compliance.
This page provides a functional simulation of an Amazon top products review search tool with Excel export in a single HTML file, meeting your requirement for 5–50 products. For real-time Amazon data, integrate the PA-API as described.
Social Plugin