| 1 | import { chromium, firefox } from "playwright"; |
| 2 | |
| 3 | export async function scrapeAirlines |
| 4 | // Launch browser |
| 5 | const browser = |
| 6 | headless: false, // |
| 7 | timeout: 0, |
| 8 | }); |
| 9 | |
| 10 | try { |
| 11 | // Create new page |
| 12 | const page = |
| 13 | |
| 14 | /** |
| 15 | * USE THIS AT YOUR OWN RISK |
| 16 | */ |
| 17 | // Navigate to airlines page |
| 18 | await page.goto |
| 19 | waitUntil: "domcontentloaded", |
| 20 | }); |
| 21 | |
| 22 | // Wait for the table to load |
| 23 | await page.waitForSelector |
| 24 | |
| 25 | // Extract airline data |
| 26 | const airlines = |
| 27 | const rows = |
| 28 | return Array.from |
| 29 | .map((row) |
| 30 | const cells = |
| 31 | if (cells.length |
| 32 | |
| 33 | // Extract airline info |
| 34 | const nameLink = |
| 35 | return { |
| 36 | name: cells[2] |
| 37 | code: cells[2] |
| 38 | fleet: cells[3] |
| 39 | }; |
| 40 | }) |
| 41 | .filter((airline) |
| 42 | }); |
| 43 | |
| 44 | // Output results |
| 45 | console.log("Found airlines: |
| 46 | Bun.write("data.json |
| 47 | |
| 48 | return airlines; |
| 49 | } catch (error) |
| 50 | console.error("Error scraping airlines: |
| 51 | throw error; |
| 52 | } finally { |
| 53 | // Always close browser |
| 54 | await browser.close |
| 55 | } |
| 56 | } |