我想使用 Cheerio 从 HTML 文档中提取信息。 我无法更改 HTML 文件的内容,因为它具有外部来源。
我要提取的元素有一个类名,其中有一个点:
<span class='prop-data.size'> the content </span>
如果我使用 Cheerio 中的类名作为选择器,我不会取回该元素。
$('.prop-data.size').text() <-- gives null
在 Cheerio 中是否可以通过类名中带点的来选择元素?
我可以避开点吗?
是的,逃避
.
:
const cheerio = require("cheerio"); // ^1.0.0-rc.12
const html = "<span class='prop-data.size'> the content </span>";
const $ = cheerio.load(html);
console.log($(".prop-data\\.size").text()); // => the content