如何解决Cheerio无法获取文本数据
我正在尝试从网站DOM节点获取文本值,并且正在关注一些Google示例,但无法获取文本。
const cheerio = require('cheerio');
const request = require('request-promise');
async function iniciar() {
const $doc = await request({
uri: '*******************',transform: body => cheerio.load(body)
});
const coat_price = $doc('#product-info > div > span.product-content-info-offer-price.offer-price.offer-price-js.product-price-amount-js');
console.log(coat_price)
console.log(coat_price.text())
}
这是输出的数据字典。 所选文本输出为空格。
initialize {
'0': {
type: 'tag',name: 'span',namespace: 'http://www.w3.org/1999/xhtml',attribs: [Object: null prototype] {
class: 'product-content-info-offer-price offer-price offer-price-js product-price-amount-js','data-amount': ''
},'x-attribsNamespace': [Object: null prototype] {
class: undefined,'data-amount': undefined
},'x-attribsPrefix': [Object: null prototype] {
class: undefined,children: [ [Object] ],parent: {
type: 'tag',name: 'div',attribs: [Object: null prototype],'x-attribsNamespace': [Object: null prototype],'x-attribsPrefix': [Object: null prototype],children: [Array],parent: [Object],prev: [Object],next: [Object]
},prev: {
type: 'text',data: '\n\t\t\n\t\t',prev: null,next: [Circular]
},next: {
type: 'text',data: '\n\t\t\n\t\t\t\t',prev: [Circular],next: [Object]
}
} .....
}
有人知道会发生什么吗? 感谢您的阅读!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。