10/02/19 23:11:30
>>729
// F#
open System.Text.RegularExpressions
let paternal last =
use client = new System.Net.WebClient()
let rec paternal' url =
seq {
let page = "URLリンク(www.jbis.or.jp)" + url + "pedigree/" |> client.DownloadString
let firstRow = Regex.Match(page, @"<tr>(.+?)</tr>", RegexOptions.Singleline).Groups.[1].Value
let horses = Regex.Matches(firstRow, @"<(?:td|th).*?><a href=""(.+?)"">(.+?)</a>")
|> Seq.cast<Match> |> Seq.map (fun m -> (m.Groups.[1].Value, m.Groups.[2].Value))
|> Seq.cache
yield! Seq.map snd horses
yield! Seq.nth (Seq.length horses - 1) horses |> fst |> paternal' }
let horses = paternal' "/horse/0000742976/" |> Seq.cache
Seq.take (Seq.findIndex ((=) last) horses + 1) horses
paternal "Eclipse" |> Seq.iter (printfn "%s")