lib.ts 653 B

1234567891011121314151617181920212223242526272829
  1. import z from 'zod'
  2. import { chromium } from 'playwright'
  3. import LLMScraper from '../src'
  4. // Create a new browser instance
  5. const browser = await chromium.launch()
  6. // Initialize the LLMScraper instance
  7. const scraper = new LLMScraper(browser)
  8. // Define schema to extract contents into
  9. const schema = z.object({
  10. title: z.string().describe('Title of the page'),
  11. })
  12. // URLs to scrape
  13. const urls = ['https://example.com', 'https://browserbase.com']
  14. // Run the scraper
  15. const pages = await scraper.run(urls, {
  16. schema,
  17. mode: 'text',
  18. closeOnFinish: true,
  19. })
  20. // Stream the result from LLM
  21. for await (const page of pages) {
  22. console.log(page.data)
  23. }