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 ?
CodePudding user response:
You can use:
const res = await fetch("www.example.com", {
headers:{
"Content-Type":"text/html"
}
});
const html = await res.text()
CodePudding user response:
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)