-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
opam
103 lines (88 loc) · 2.89 KB
/
opam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
opam-version: "2.0"
description: """
Mechaml is a functional web scraping library that allows to :
* Fetch web content
* Analyze, fill and submit HTML forms
* Handle cookies, headers and redirections
Mechaml is built on top of existing libraries that provide low-level features : [Cohttp](https://github.com/mirage/ocaml-cohttp) and
[Lwt](https://github.com/ocsigen/lwt) for asynchronous I/O and HTTP handling, and
[Lambdasoup](https://github.com/aantron/lambda-soup) to parse HTML. It provides
an interface that handles the interactions between these and add a few
other features.
## Overview
The library is divided into 3 main modules :
* Agent : User-agent features. Perform requests, get back content, headers, status code, ...
* Cookiejar : Cookies handling
* Page : HTML parsing and forms handling
The Format module provides helpers to manage the formatted content in forms such
as date, colors, etc. For more details, see the [documentation](https://yannham.github.io/mechaml/)
## Installation
### From opam
```
opam install mechaml
```
### From source
Mechaml uses the dune build system, which can be installed through opam. Then,
just run
```
dune build
```
to build the library.
Use `dune build @doc` to generate the documentation, `dune runtest` to build and
execute tests, and `dune build examples/XXX.exe` to compile example XXX.
## Usage
Here is sample of code that fetches a web page, fills a login form and submits
it in the monadic style:
```ocaml
open Mechaml
module M = Agent.Monad
open M.Infix
let require msg = function
| Some a -> a
| None -> failwith msg
let action_login =
Agent.get "http://www.somewebsite.com"
>|= Agent.HttpResponse.page
>|= (function page ->
page
|> Page.form_with "[name=login]"
|> require "Can't find the login form !"
|> Page.Form.set "username" "mynick"
|> Page.Form.set "password" "@xlz43")
>>= Agent.submit
let _ =
M.run (Agent.init ()) action_login
```
More examples are available in the dedicated folder."""
maintainer: "Yann Hamdaoui <yann.hamdaoui@gmail.com>"
authors: "Yann Hamdaoui <yann.hamdaoui@gmail.com>"
license: "LGPL-3.0-only"
homepage: "https://github.com/yannham/mechaml"
doc: "https://yannham.github.io/mechaml/"
bug-reports: "https://github.com/yannham/mechaml/issues"
depends: [
"dune" {>= "1.1.0"}
"cohttp" {>= "0.21.0" & < "2.0.0"}
"cohttp-lwt"
"cohttp-lwt-unix"
"lwt"
"uri" {< "3.0.0"}
"lambdasoup" {< "0.7.0"}
"alcotest" {with-test & >= "0.8.0" & < "1.4.0"}
"ocaml" {>= "4.03.0"}
]
build: [
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
["make doc"] {with-doc}
]
dev-repo: "git+https://github.com/yannham/mechaml.git"
url {
src:
"https://github.com/yannham/mechaml/releases/download/v1.1.0/mechaml-v1.1.0.tbz"
checksum: [
"sha256=9071f8ebeeaf438427ce401ddaf3acc7231a24108af63128cd52b07b239e7f70"
"md5=6ce800fbcdd8bdb53c84fb5e4bfb0329"
]
}
synopsis: ""