'How do I get html response from axios?
I want to run some html parsing on a page.I want to know if I can get the whole html page source code as a response. I think I will be using node-html-parser npm package. I want my axios response in the 2 line after parse.(2nd image.) To be more specific I want to parse this website https://mojapp.in/@shiviverma6263 to get the follower count of a user. Axios is giving me errors.
I want something Like when postman gives the html of that website if i just run a simple get request to that page.
axios.get('https://mojapp.in/@piyanka_mongia', {
params: {
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// always executed
});
[postman][1]
import { parse } from 'node-html-parser';
const root = parse('<ul id="list"><li>Hello World</li></ul>');
console.log(root.firstChild.structure);
// ul#list
// li
// #text
console.log(root.querySelector('#list'));
// { tagName: 'ul',
// rawAttrs: 'id="list"',
// childNodes:
// [ { tagName: 'li',
// rawAttrs: '',
// childNodes: [Object],
// classNames: [] } ],
// id: 'list',
// classNames: [] }
console.log(root.toString());
// <ul id="list"><li>Hello World</li></ul>
root.set_content('<li>Hello World</li>');
root.toString(); // <li>Hello World</li>```
[1]: https://i.stack.imgur.com/vDAyR.png
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|