-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpackage.yaml
82 lines (77 loc) · 2.51 KB
/
package.yaml
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
name: hs-scrape
version: 0.1.0.1
github: "httpscodygman/hs-scrape"
license: MIT
author: "Cody Goodman"
maintainer: "[email protected]"
# Metadata used when publishing your package
synopsis: Simple and easy web scraping and automation in Haskell.
category: Web
description: |
Shpider/mechanize inspired web automation with a focus on convenience for web scraping.
.
A fully functional example of logging into paypal and getting your account balance (<https://github.com/codygman/hs-scrape-paypal-login cabal buildable repo of this example>):
.
> import Control.Applicative
> import Control.Monad
> import Control.Monad.IO.Class
> import Data.Maybe
> import Data.Monoid
> import qualified Data.Text as T
> import Data.Text.IO (putStrLn)
> import Network.Scraper.State
> import Prelude hiding (putStrLn)
> import Text.XML.Cursor (attributeIs, content, element, ($//),
> (&/))
>
> getPaypalBalance cursor = fromMaybe (error "Failed to get balance") $ listToMaybe $
> cursor $//
> element "div" >=> attributeIs "class" "balanceNumeral" &/
> element "span" >=> attributeIs "class" "h2" &/
> content
>
> main = do
> runScraper $ do
> get "https://www.paypal.com/login"
>
> postToForm (Name "login_form") (Just creds) AllVisible
>
> get "https://www.paypal.com/myaccount/home"
>
> cursor <- liftM (fromMaybe (error "Couldn't get cursor")) getCurrentCursor
> liftIO . putStrLn $ "Your Paypal balance is: " <> getPaypalBalance cursor
>
> where creds = [ ("login_email", "[email protected]") -- put your credentials here
> , ("login_password", "password")]
.
dependencies:
- base >= 4.7 && < 5
- bytestring
- text
- wreq
- html-conduit
- xml-conduit
- safe
- transformers
- lens
- containers
- url
- hspec
- retry
- data-default
- exceptions
library:
source-dirs: src
tests:
hs-scrape-test:
main: Tests.hs
source-dirs: tests
dependencies:
- hs-scrape
- base
- tasty
- hspec
- tasty-hunit
- hs-scrape
- xml-conduit
- containers