javascript - Cheerio 无法获取文本数据
问题描述
我正在尝试从网站 DOM 节点获取文本值,并且我正在关注一些谷歌示例,但我无法获取文本。
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,
'data-amount': undefined
},
children: [ [Object] ],
parent: {
type: 'tag',
name: 'div',
namespace: 'http://www.w3.org/1999/xhtml',
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',
parent: [Object],
prev: null,
next: [Circular]
},
next: {
type: 'text',
data: '\n\t\t\n\t\t\t\t',
parent: [Object],
prev: [Circular],
next: [Object]
}
} .....
}
有人知道会发生什么吗?谢谢阅读!
解决方案
推荐阅读
- rest - 如何最好地定义一个带有动词的 REST 端点?
- linux - 我不能用 arm-none-eabi-gcc 编译
- bash - 正确使用grep
- amazon-web-services - 将 AWS CLI 从 1 更改为 2
- node.js - 如何使用路由参数和查询参数在 express 中创建 api
- javascript - 递归修剪对象中所有元素的更好方法?
- android - Flutter中——如何传递从url下载的图片
- java - 将类型为 class 的变量分配给扩展声明的变量类型的不同类
- wpf - 刷新视图时,CollectionView.filter 委托未触发
- python-3.x - 从 varchar2 到日期的 Python cx_oracle 转换 - 错误“sqlalchemy.exc.DatabaseError: (cx_Oracle.DatabaseError) ORA-01861”