Created
December 9, 2025 21:56
-
-
Save niradler/e12e8a06cf5665efb55ac5f0b596ad2a to your computer and use it in GitHub Desktop.
AliExpress Order Scraper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // AliExpress Order Scraper - Browser Console Script | |
| // Paste this into the browser console on https://www.aliexpress.com/p/order/index.html | |
| async function scrapeAliExpressOrders() { | |
| const orders = []; | |
| let loadMoreAttempts = 0; | |
| const maxAttempts = 100; // Safety limit | |
| console.log('Starting AliExpress order scraping...'); | |
| // Function to wait for elements to load | |
| const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | |
| // Function to click "Load More" button | |
| async function loadAllOrders() { | |
| while (loadMoreAttempts < maxAttempts) { | |
| const loadMoreButton = document.querySelector('#root > div.order-wrap > div.order-main > div.order-more > button'); | |
| if (!loadMoreButton || loadMoreButton.disabled || !loadMoreButton.offsetParent) { | |
| console.log('No more orders to load or button not found'); | |
| break; | |
| } | |
| console.log(`Loading more orders... (attempt ${loadMoreAttempts + 1})`); | |
| loadMoreButton.click(); | |
| loadMoreAttempts++; | |
| // Wait for new orders to load | |
| await wait(2000); | |
| } | |
| } | |
| // Load all orders first | |
| await loadAllOrders(); | |
| await wait(1000); | |
| console.log('Extracting order data...'); | |
| // Get all order containers | |
| const orderContainers = document.querySelectorAll('#root > div.order-wrap > div.order-main > div.order-content > div > div'); | |
| console.log(`Found ${orderContainers.length} orders`); | |
| orderContainers.forEach((orderContainer, index) => { | |
| try { | |
| const order = {}; | |
| // Extract order date | |
| const dateElement = orderContainer.querySelector('.order-item-header-right > div > div:nth-child(1)'); | |
| order.orderDate = dateElement ? dateElement.textContent.trim() : 'N/A'; | |
| // Extract order ID (from the container or header) | |
| const orderIdElement = orderContainer.querySelector('.order-item-header-left'); | |
| order.orderId = orderIdElement ? orderIdElement.textContent.replace('Order', '').trim() : `order_${index + 1}`; | |
| // Extract status | |
| const statusElement = orderContainer.querySelector('.order-item-header-right'); | |
| const statusText = statusElement ? statusElement.textContent : ''; | |
| order.status = statusText.replace(order.orderDate, '').trim(); | |
| // Extract total price | |
| const priceElement = orderContainer.querySelector('.order-item-content-opt-price > span > div'); | |
| order.totalPrice = priceElement ? priceElement.textContent.trim() : 'N/A'; | |
| // Extract store name | |
| const storeElement = orderContainer.querySelector('.order-item-header-left a'); | |
| order.storeName = storeElement ? storeElement.textContent.trim() : 'N/A'; | |
| // Extract products | |
| order.products = []; | |
| // Check if there's a single product name (text-based) | |
| const singleProductName = orderContainer.querySelector('.order-item-content-info-name > a > span'); | |
| if (singleProductName) { | |
| // Single product order | |
| const product = { | |
| name: singleProductName.textContent.trim(), | |
| quantity: 1 | |
| }; | |
| // Try to get product image | |
| const productImage = orderContainer.querySelector('.order-item-content-info-img img'); | |
| if (productImage) { | |
| product.imageUrl = productImage.src; | |
| } | |
| // Try to get product link | |
| const productLink = orderContainer.querySelector('.order-item-content-info-name > a'); | |
| if (productLink) { | |
| product.url = productLink.href; | |
| } | |
| order.products.push(product); | |
| } else { | |
| // Multiple products - they appear as image thumbnails | |
| const productLinks = orderContainer.querySelectorAll('.order-item-content-body > div > a'); | |
| productLinks.forEach((productLink) => { | |
| const product = {}; | |
| // Get product image and title from the link | |
| const img = productLink.querySelector('img'); | |
| if (img) { | |
| product.imageUrl = img.src; | |
| product.name = img.alt || img.title || 'Product'; | |
| } | |
| product.url = productLink.href; | |
| order.products.push(product); | |
| }); | |
| } | |
| // Extract buttons/actions available | |
| order.actions = []; | |
| const buttons = orderContainer.querySelectorAll('.order-item-content-opt button, .order-item-content-opt a'); | |
| buttons.forEach(button => { | |
| order.actions.push(button.textContent.trim()); | |
| }); | |
| orders.push(order); | |
| } catch (error) { | |
| console.error(`Error extracting order ${index + 1}:`, error); | |
| } | |
| }); | |
| console.log(`Successfully extracted ${orders.length} orders`); | |
| return orders; | |
| } | |
| // Run the scraper | |
| scrapeAliExpressOrders().then(orders => { | |
| console.log('Orders scraped successfully!'); | |
| console.log(JSON.stringify(orders, null, 2)); | |
| // Download as JSON file | |
| const dataStr = JSON.stringify(orders, null, 2); | |
| const dataBlob = new Blob([dataStr], { type: 'application/json' }); | |
| const url = URL.createObjectURL(dataBlob); | |
| const link = document.createElement('a'); | |
| link.href = url; | |
| link.download = `aliexpress_orders_${new Date().toISOString().split('T')[0]}.json`; | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| URL.revokeObjectURL(url); | |
| console.log('JSON file downloaded!'); | |
| // Also make it available in the console | |
| window.aliexpressOrders = orders; | |
| console.log('Orders also available as: window.aliexpressOrders'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment