0

是否可以使用 jsdom 获取多行属性的值(我将它与 Node.js+JQuery 一起使用)?

要抓取的站点包括以下 HTML:

<li><a data-title="<strong>hello world
this is a test</strong>" href="example.org</strong>">A link</a></li>

不幸的是,这被解析为

<li><a data-title="data-title"><strong>hello world
this is a test</strong>' href="example.org">A link</a></li>

所以我无法提取标题和 href 属性,例如通过 JQuery: $("a").attr("data-title")

有任何想法吗?

4

1 回答 1

0

是的,这是jsdom解析器中的一个错误。这是因为它没有使用完全符合 HTML5 的解析器。您可以看到此类错误仍未解决:

  1. https://github.com/tmpvar/jsdom/issues/494
  2. https://github.com/tmpvar/jsdom/issues/482

您可以尝试用cheerio进行刮擦。

于 2013-03-17T07:04:13.443 回答