为了从axios获取HTML响应,我们需要使用axios的responseType选项。将响应类型设置为“document”可以让axios解析响应并返回一个DOM文档对象,可以像使用浏览器DOM API一样检索和操作响应内容。以下是一个示例:
axios({
method: 'get',
url: 'https://example.com',
responseType: 'document'
})
.then(function(response) {
console.log(response.data); // DOM document object
})
.catch(function(error) {
console.error(error);
});