我目前正在使用 node.js 抓取一个保存为 .htm 的 word 文档,然后为 shell 重写它。
我已经创建了
$("p","td:nth-child(2)").each(function(){
var marginLeft = this.css("margin-left");
}
到目前为止,我的效果非常好。我面临的唯一麻烦是样式实际上是通过类应用的。
这是冲突的类:
p.RNBullet1, li.RNBullet1, div.RNBullet1{
mso-style-name:"*RN Bullet1";
mso-style-unhide:no;
mso-style-link:"*RN Bullet1 Char";
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.2in;
text-indent:-.2in;
mso-pagination:widow-orphan;
mso-list:l12 level1 lfo5;
font-size:11.0pt;
font-family:"Arial","sans-serif";
mso-fareast-font-family:"Times New Roman";
}
当它显然有值时,它会返回一个未定义的值。
对此的任何见解都会有所帮助,我在这里发疯了。
最佳答案
正如 vkurchatkin 上面指出的,cheerio 只是遍历 DOM。它不读取样式表
这是答案:https://npmjs.org/package/juice
基本上,我将返回的果汁加载到 cheerio 中。
果汁会将麦粒肿变成内联。
关于javascript - Cheerio.js 没有抓取非内联样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21567064/