npm install axios
In the code below, we crawl a html document, and extract the title text from it.
import axios from 'axios'
export async function CrawlDemo(url) {
const { data } = await axios.get(url, {
responseType: 'document'
})
return data.querySelector('h1').innerText.trim()
}
Notice:
responseType: 'document'
option to axios, so that the returned data
is a document
.querySelector
on the returned data
object.