search steam store

This commit is contained in:
Fabien Freling 2020-05-06 00:15:15 +02:00
commit fe419d7705
4 changed files with 51 additions and 0 deletions

3
src/dune Normal file
View file

@ -0,0 +1,3 @@
(executable
(name main)
(libraries mechaml))

28
src/main.ml Normal file
View file

@ -0,0 +1,28 @@
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")