首页 > 解决方案 > F# - 使用 HtmlProvider 加载最后一行为空的表时出错

问题描述

使用 HtmlProvider 加载 Wikipedia 表时,我收到一条错误消息,因为表中的最后一行是空的!

module SOQN = 

    open System
    open FSharp.Data

    let [<Literal>] wikiUrl  = @"https://en.wikipedia.org/wiki/COVID-19_testing#Virus_testing_statistics_by_country"
    type Covid = HtmlProvider<wikiUrl>

    let main() =
        printfn ""
        printfn "SOQN: Error Loading Table With Empty Last Row Using HtmlProvider?"
        printfn ""
        let feed = Covid.Load(wikiUrl)
        feed.Tables.``Virus testing statistics by country``.Rows
        |> Seq.map (fun r -> r.Date) 
        |> printf "%A "
        printfn ""
        0

    [<EntryPoint>]
    main() |> ignore
    printfn "Fini!"
    printfn ""

// Actual Output: 
// "Date is missing"
// 
// Expected Output: 
// seq [ "Albania"; "19 Apr"; "5542"; "562"; "10.1"; "1,936"; "196"; "[121]" ]
// ... 
//

我错过了什么?

例如,我可以将列类型预设为“字符串”,类似于在 CsvProvider 中使用“模式”吗?

标签: f#-data

解决方案


推荐阅读