Parsing the result obtained from mochiweb_html

大城市里の小女人 提交于 2019-12-04 15:29:48

You could use mochiweb_xpath:

> mochiweb_xpath:execute("//span[@id='footer']",
    mochiweb_html:parse(
      "<html><body><span>not this one</span><span id='footer'>but this one</span></body></html>")).
[{<<"span">>,
  [{<<"id">>,<<"footer">>}],
  [<<"but this one">>]}]

It depends on your performance requirements.

The mochiweb result is in a 3-tuple form that could probably fairly easily be converted to input suitable for xmerl. Most of the work would be converting attribute names to atoms. Then you could use xmerl_xpath to do some pretty flexible querying.

Otherwise you could code something less flexible (but maybe faster) to walk the tree.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!