| 492 | } |
| 493 | |
| 494 | export function getURLsFromXML(xmlBody: string, limit: number): string[] { |
| 495 | const dom = new JSDOM(xmlBody, { contentType: 'text/xml' }) |
| 496 | const linkElements = dom.window.document.querySelectorAll('url') |
| 497 | const urls: string[] = [] |
| 498 | for (const linkElement of linkElements) { |
| 499 | const locElement = linkElement.querySelector('loc') |
| 500 | if (limit !== 0 && urls.length === limit) break |
| 501 | if (locElement?.textContent) { |
| 502 | urls.push(locElement.textContent) |
| 503 | } |
| 504 | } |
| 505 | return urls |
| 506 | } |
| 507 | |
| 508 | export async function xmlScrape(currentURL: string, limit: number): Promise<string[]> { |
| 509 | let urls: string[] = [] |