Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.27 KB | None | 0 0
  1. #r @"..\packages\FSharp.Data.2.2.5\lib\net40\FSharp.Data.dll"
  2.  
  3. open FSharp.Data
  4. open System.Text.RegularExpressions
  5.  
  6. let alphabet = ["a"; "b"; "v"; "g"; "d"; "e"; "jo"; "zh"; "z"; "i"; "k"; "l"; "m"; "n"; "o"; "p"; "r"; "s"; "t"; "u"; "f"; "kh"; "c"; "ch"; "sh"; "shch"; "eh"; "ju"; "ja"]
  7. let getUri = sprintf "http://old-abiturient.urfu.ru/applicant/master-2015/alpha/%s/"
  8.  
  9. type Spec = {Title: string; Priority: int}
  10. type Abiturient = {Name: string; N: string; Spec: Spec list}
  11.  
  12. let peoples = alphabet
  13.               |> List.take 1
  14.               |> List.map getUri
  15.               |> List.map HtmlDocument.Load
  16.               |> List.collect (fun x -> x.Descendants "table"
  17.                                         |> Seq.exactlyOne
  18.                                         |> fun t -> t.Elements "tr"
  19.                                         |> Seq.skip 1
  20.                                         |> Seq.fold
  21.                                             (fun (accList, tempList, hClass) e ->
  22.                                                 match e.AttributeValue "class" with
  23.                                                 | c when c = hClass -> (accList, e.Elements () :: tempList, hClass)
  24.                                                 | c -> (tempList :: accList, [e.Elements ()], c)) ([[]], [], "tr-even")
  25.  
  26.                                         |> fun (c, _, _) -> c |> List.rev |> List.map List.rev
  27.                                         |> List.tail
  28.                                         |> List.map
  29.                                             (fun nodes -> {Name = nodes.[0].[0].InnerText (); N = nodes.[0].[1].InnerText ();
  30.                                                             Spec = [{Title = nodes.[0].[5].InnerText (); Priority = 0}]
  31.                                                             @ (nodes
  32.                                                                 |> List.skip 1
  33.                                                                 |> List.mapi (fun i n-> {Title = n.[3].InnerText (); Priority = i + 1}))}
  34.                                                               )
  35.                                         )
  36.             |> List.filter (fun ab -> ab.Spec |> List.exists (fun spec -> spec.Title.Contains "ИМКН"))
  37. printf "%A" peoples.[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement