Erlang:从解析的html中获取信息

时间:2015-01-07 17:16:23

标签: json parsing erlang extract

我的项目仍然是编码。但不幸的是我遇到了另一个问题。

最近,我设法从网站上获取带有erlang的html代码,并在mochiweb插件中解析该信息。 这里现在有了:

    {<<"html">>,[],
 [{<<"head">>,[],[]},
  {<<"body">>,[],
   [{<<"table">>,[],
     [{<<"tr">>,[],
       [{<<"td">>,[{<<"id">>,<<"day">>}],[<<"Poniedzialek ">>]},
        {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" -5 ">>]},
        {<<"td">>,[{<<"id">>,<<"wiatr">>}],[<<"13 km/h">>]}]},
      {<<"tr">>,[],
       [{<<"td">>,[{<<"id">>,<<"day">>}],[<<"Wtorek ">>]},
        {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" -15 ">>]},
        {<<"td">>,[{<<"id">>,<<"wiatr">>}],[<<"13 km/h">>]}]},
      {<<"tr">>,[],
       [{<<"td">>,[{<<"id">>,<<"day">>}],[<<"Sroda ">>]},
        {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" 10 ">>]},
        {<<"td">>,[{<<"id">>,<<"wiatr">>}],[<<"13 km/h">>]}]},
      {<<"tr">>,[],
       [{<<"td">>,[{<<"id">>,<<"day">>}],[<<"Czwartek ">>]},
        {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" 12 ">>]},
        {<<"td">>,[{<<"id">>,<<"wiatr">>}],[<<"13 km/h">>]}]},
      {<<"tr">>,[],
       [{<<"td">>,[{<<"id">>,<<"day">>}],[<<"Piatek ">>]},
        {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" 20 ">>]},
        {<<"td">>,[{<<"id">>,<<"wiat"...>>}],[<<"13 km/h">>]}]},
      {<<"tr">>,[],
       [{<<"td">>,[{<<"id">>,<<"day">>}],[<<"Poniedzialek"...>>]},
        {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" -5 ">>]},
        {<<"td">>,[{<<"id">>,<<...>>}],[<<"13 k"...>>]}]}]}]}]}

现在我想提取有关温度,风的信息。如何在erlang中使函数在列表中获得准确的温度或添加到json文件中,而不需要任何不必要的东西。

1 个答案:

答案 0 :(得分:0)

现在我有了:

[{<<"td">>,[{<<"id">>,<<"temp">>}],[<<" -5 ">>]},
 {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" -15 ">>]},
 {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" 10 ">>]},
 {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" 12 ">>]},
 {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" 20 ">>]},
 {<<"td">>,[{<<"id">>,<<"temp">>}],[<<" -5 ">>]}]

好的,我知道了:

[<<" -5 ">>]

如何仅提取-5?