1

Enlive を使用してイベント リストを解析しようとしています。

通常、各イベント データは特定の div (ここでは「結果」) に分離されます。

<div class="result">
  <h3>Event 1 title</h3>
  <a href="http://the_site.com/event1">Event 1 page</a>
  <p>Event 1 location</p>
</div>
<div class="result">
  <h3>Event 2 title</h3>
  <a href="http://the_site.com/event2">Event 2 page</a>
  <p>Event 2 location</p>
</div>

そこで、各イベント サイトのすべての解析ロジックを持つ変数を作成しました。

(def parsing-config 
  {:source "The Site"
   :results-url ["http://the_site.com"]
   :parsing {
     :title {:selector [[div.result] [:h3]]
             :trim-fn (comp first :content)}
     :url {:selector [[div.result] [:a]]
           :trim-fn (:href (:attrs %))}
     :location {:selector [[div.result] [:p]]
                :trim-fn (comp first :content)}}
    {:source "Other event site"
     ...}})

しかし、特定のサイトでは、次のように複数のイベントを含む div があります。

<div class="September">
  <h3>Event 1 title</h3>
  <a href="http://other_site.com/event1">Event 1 page</a>
  <p>Event 1 location</p>
  <h3>Event 2 title</h3>
  <a href="http://other_site.com/event2">Event 2 page</a>
  <p>Event 2 location</p>
</div>
<div class="October">
  <h3>Event 3 title</h3>
  <a href="http://other_site.com/event3">Event 3 page</a>
  <p>Event 3 location</p>
  <h3>Event 4 title</h3>
  <a href="http://other_site.com/event4">Event 4 page</a>
  <p>Event 4 location</p>
</div>

この最後のサイトの各イベントを解析するにはどうすればよいですか? parsing-config 変数のみを変更し、解析に使用する関数は変更しません (ここには示されていません...)。

ありがとう。

注::trim-fn関数は正確ではない場合があります。

4

0 に答える 0