0

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?

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Srushti Shah
  • 810
  • 3
  • 17

2 Answers2

0

You can use:

const res = await fetch("www.example.com", {
  headers:{
    "Content-Type":"text/html"
  }
});

const html = await res.text()

0

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)
Srushti Shah
  • 810
  • 3
  • 17