我可以在cheerio中获取HTML元素的CSS属性值

时间:2018-10-26 11:50:07

标签: cheerio

<head>
    <meta charset="utf-8" />
    <title>Hi there.</title>
    <style>
        p {margin: 10px; padding: 20px; width: 500px; line-height: 23px;}
    </style>
</head>
<body>
    <p>What is the capital of Australia?</p>
</body>

如何在上面的以下代码中获取保证金值?

每次我执行以下操作: $('p')。css('padding') //我希望输出为20px;但是

出现以下错误:

var styles = parse(el.attribs.style);                         ^

TypeError:无法读取未定义的属性“ attribs”     在getCss(C:\ Users \ BBNH \ Desktop \ webscrapping \ node_modules \ cheerio \ lib \ api \ css.js:69:25)     在initialize.exports.css(C:\ Users \ BBNH \ Desktop \ webscrapping \ node_modules \ cheerio \ lib \ api \ css.js:25:12)     在Node。$。find.each(C:\ Users \ BBNH \ Desktop \ webscrapping \ scrape1.js:138:22)     在initialize.exports.each处(C:\ Users \ BBNH \ Desktop \ webscrapping \ node_modules \ cheerio \ lib \ api \ traversing.js:300:24)     在Node。$。find.each(C:\ Users \ BBNH \ Desktop \ webscrapping \ scrape1.js:131:16)     在initialize.exports.each处(C:\ Users \ BBNH \ Desktop \ webscrapping \ node_modules \ cheerio \ lib \ api \ traversing.js:300:24)     在Node。$。each(C:\ Users \ BBNH \ Desktop \ webscrapping \ scrape1.js:128:12)     在initialize.exports.each处(C:\ Users \ BBNH \ Desktop \ webscrapping \ node_modules \ cheerio \ lib \ api \ traversing.js:300:24)     在Request.request [作为_callback](C:\ Users \ BBNH \ Desktop \ webscrapping \ scrape1.js:125:46)     在Request.self.callback(C:\ Users \ BBNH \ Desktop \ webscrapping \ node_modules \ request \ request.js:185:22)

0 个答案:

没有答案