Well stepping back a bit, its easier to extract text from a webpage using things like document.querySelector, which completely avoid all these issues with HTML entity decoding.
There are probably plenty of examples here, but you could start by looking at a contribution like: