我想解析HTML文件中的一些內容(無xml)。解析從mochiweb_html獲得的結果
在我檢索結構中使用mochiweb_html來解析一下:
1> inets:start().
2> {ok, {Status, Headers, Body}} = httpc:request("http://www.google.com").
3> {String, Attributes, Other} = mochiweb_html:parse(Body).
,結果是一樣的東西:
{<<"html">>,
[{<<"itemscope">>,<<"itemscope">>},
{<<"itemtype">>,<<"http://schema.org/WebPage">>}],
[{<<"head">>,[],
[{<<"meta">>,
[{<<"itemprop">>,<<"image">>},
{<<"content">>,<<"/images/google_favicon_128.png">>}],
[]},
{<<"title">>,[],[<<"Google">>]},
....
什麼是從mochiweb_http得到的結構檢索的最佳方式網頁中具有特定標籤的所有元素(例如,<span id="footer">
)?
如此。只需走樹就可以得到你需要的東西。 – 2013-04-23 06:06:30
你能舉個例子嗎?我被卡住了:( – user601836 2013-04-23 08:16:26
我更喜歡@legoscia提供的解決方案,我不知道mochiweb_xpath。 – EdF 2013-04-23 16:17:31