jsdom的多行属性

时间:2013-03-16 22:32:21

标签: javascript node.js web-scraping screen-scraping jsdom

是否可以使用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")

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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

  1. https://github.com/tmpvar/jsdom/issues/494
  2. https://github.com/tmpvar/jsdom/issues/482
  3. 您可以尝试cheerio进行抓取。