Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Created February 12, 2015 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamessdixon/93a8fdd5ff56e9a51670 to your computer and use it in GitHub Desktop.
Save jamessdixon/93a8fdd5ff56e9a51670 to your computer and use it in GitHub Desktop.
Scraping Wake County Tax Site Using F#
#r "../packages/FSharp.Data.2.1.1/lib/net40/FSharp.Data.dll"
open System.IO
open FSharp.Data
type context = HtmlProvider<"../data/RealEstateSample.html">
type houseValuation = {addressOne:string; addressTwo:string; addressThree:string; assessedValue:string}
let createUri(id: int) =
"http://services.wakegov.com/realestate/Account.asp?id=" + id.ToString("D7")
let getValuation(uri: string)=
try
let body = context.Load(uri).Html.Body()
let tables = body.Descendants("TABLE") |> Seq.toList
let addressTable = tables.[7]
let fonts = addressTable.Descendants("font") |> Seq.toList
let addressOne = fonts.[1].InnerText()
let addressTwo = fonts.[2].InnerText()
let addressThree = fonts.[3].InnerText()
let taxTable = tables.[11]
let fonts' = taxTable.Descendants("font") |> Seq.toList
let assessedValue = fonts'.[3].InnerText()
let result = JsonValue.Record [|
"addressOne", JsonValue.String addressOne
"addressTwo", JsonValue.String addressTwo
"addressThree", JsonValue.String addressThree
"assessedValue", JsonValue.String assessedValue |]
Some result
with
| :? System.ArgumentException -> None
let writeValuation(valuation: option<JsonValue>) =
match valuation.IsSome with
| true -> File.AppendAllText(@"C:\Data\data.json",valuation.Value.ToString() + "," )
| false -> ()
let doValuation(id: int) =
createUri id
|> getValuation
|> writeValuation
|> ignore
#time
[1..100] |> Seq.iter(fun id -> doValuation id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment