UNPKG

article-parser

Version:

To extract main article from given URL

17 lines (14 loc) 459 B
// utils -> retrieve import fetch from 'cross-fetch' export default async (url) => { const res = await fetch(url, { headers: { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0' } }) const contentType = res.headers.get('content-type') || '' if (!contentType || !contentType.includes('text/')) { throw new Error(`Content type must be "text/html", not "${contentType}"`) } return res.text() }