import { chromium } from 'playwright'; async function run(urls) { // Path to store browser data const userDataDir = './user-data'; // Launch browser with persistent context const context = await chromium.launchPersistentContext(userDataDir, { headless: true, // Run in headless mode args: ['--start-maximized'], // Optional: Additional arguments }); try { const page = context.pages().length ? context.pages()[0] : await context.newPage(); console.log(`itemid,sales,datetime`); for (const url of urls) { // Navigate to the page await page.goto( "https://www.ebay.com/bin/purchaseHistory/"+url, { waitUntil: 'domcontentloaded', }); // Check if the table exists const tableExists = await page.$('table.app-table__table'); if (!tableExists) { console.log(`${url},0,`); continue; } // Select table rows const rows = await page.$$('table.app-table__table tr'); // Array to store cell data const tableData = []; for (const row of rows) { const cells = await row.$$('td'); // Skip rows with fewer than 3 cells if (cells.length < 3) continue; const cellTexts = [url]; // Include the URL for context // Skip the first two cells and process the rest for (const cell of cells.slice(2)) { const textContent = await cell.textContent(); cellTexts.push(textContent ? textContent.trim() : ''); } if (cellTexts.length) { tableData.push(cellTexts); } } if (tableData.length === 0) { console.log(`${url},0,`); continue; } // Convert table data to CSV format const csvData = tableData.map(row => row.join(',')).join('\n'); console.log(csvData); } } catch (error) { console.error('An error occurred:', error); } finally { // Close the browser await context.close(); } } @if( isset($ids) && is_countable($ids) && count($ids)) // Run the script with example URLs run([ @foreach ($ids as $id) "{{ $id }}"@if(!$loop->last), @endif @endforeach ]).catch(console.error); @else console.error('itemid,sales,datetime'); @endif