Created
June 21, 2016 09:51
-
-
Save seryh/c554cf93cd02e3d0174b56de16412977 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#_(:require [hickory.core :as hic] | |
[hickory.select :as s] | |
[clojure.xml :as xml]) | |
(defn players->xml [] | |
(let [html (:body (client/post "http://myvolley.ru/servlet/playersearch" | |
{:form-params {:sex 0 | |
:numt 10 | |
:t_status 0 | |
:day 22 | |
:month 6 | |
:year 2015} | |
:as "CP1251"})) | |
hic-doc (hic/as-hickory (hic/parse html)) | |
players (s/select (s/child (s/id :f_players) | |
(s/tag :tbody)) hic-doc) | |
do-xml (fn [normal-data] | |
(let [xml-data (reduce (fn [coll pl] | |
(conj coll {:tag :player | |
:content [(pl :name)] | |
:attrs {:city (pl :player-city) | |
:status (pl :player-status)}})) [] normal-data)] | |
(xml/emit {:tag :players :content xml-data}) )) | |
do-normal-data (fn [item] (let [player-node (get-in item [:content]) | |
player-name (get-in player-node [0 :content 1 :content 0]) | |
player-status (get-in player-node [3 :content 0]) | |
player-city (get-in player-node [6 :content 0])] | |
(when player-name | |
{:name player-name | |
:player-status player-status | |
:player-city player-city}))) | |
normal-data (filter some? (mapv do-normal-data (get-in players [0 :content])))] | |
(do-xml normal-data))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment