vg-store/src/main.ml

29 lines
707 B
OCaml

open Mechaml
module M = Agent.Monad
open M.Infix
let require msg = function
| Some a -> a
| None -> failwith msg
let steam_search query =
let url = "https://store.steampowered.com/" in
Agent.get url
>|= (fun result ->
let form = result
|> Agent.HttpResponse.page
|> Page.form_with "[id=searchform]"
|> require "search form not found" in
let field = form
|> Page.Form.field_with "[name=term]"
|> require "q field not found" in
Page.Form.Field.set form field query)
>>= Agent.submit
>>= (fun response ->
response
|> Agent.HttpResponse.content
|> M.save_content "steam-result.html")
let _ =
M.run (Agent.init ()) (steam_search "planet")