I need to write a program in c++ that downloads webpages and then parses them and only keeps the necessary information. Libcurl seems to be the most popular way to do it. But I need it to work with both HTML and JavaScript, but I have been told the libcurl does not work with JavaScript. Is that true? If so is there another way to download webpages using c++ that works with JavaScript?
libcurl is only an HTTP/S client, not a web browser. It will download the JavaScript if you tell it to, but it won't do it automatically (e.g. if the JS is included as a resource by the HTML document), and it won't execute it, so if the JS modifies the DOM, libcurl won't know about it.
If you need something this advanced you should research how to interface with a full fledged web browser. A possibility might be Chromium or Firefox in headless mode.