Skip to content
Advertisement

How to convert URL into HTML in JavaScript?

I want a HTML document of an URL

I have URL like www.example.com and I want the HTML block of the page of URL. How can I achieve this in JavaScript I read that Java has method like IOUtils.toString to do the same. can somebody suggest me how to do this or what is the method in JavaScript as in Java?

Advertisement

Answer

I did it using @Augustine Madu’s answer I used axios to call url

        const res = await axios({
            method: 'get',
            url: url,
            headers:{
                "Content-Type":"text/html"
            },
        })
        console.log(res.data)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement