In this project I'm working on, I'm using the npm package 'request' and have a code which looks something like this
request({
url: 'https://www.google.com/'
}, (error, response, body) => {
// does stuff here
});
Now, request returns a body which is basically a long string of HTML elements which looks like
<!doctype html><html> ... </html>
What I need to do is convert that string into a DOM so that I can use methods such as getElementById()
or getElementByClassName()
so I can return whatever values those elements contain.
I know there are libraries such as cheerio which does exactly what I need, but as of this moment I can't use those packages yet so I need to try and find a way to implement this with vanilla javascript.