Been getting back into programming after a pretty long while, I decided I would play around with http requests in javascript to build a web scraper later, I wrote this little guy to practice a bit:
var DOMParser = require('xmldom').DOMParser;
fetch('http://books.toscrape.com/index.html')
.then(response => {
return response.text()
})
.then(html => {
const parser = new DOMParser()
const doc = parser.parseFromString(html, "text/html")
const elem = doc.querySelector('.thumbnail').innerHTML
console.log(elem)
})
.catch(error => {
console.error('error:', error)
})
This returns the following error:
error: TypeError: doc.querySelector is not a function
at /home/petal/Desktop/scrapetest.js:11:22
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)