Something went wrong. Try again.
scraping + BEAM.
Something went wrong. Try again.
Files
- Gleam 96%
- Erlang 4%
README.md
scream #
Web scraping for Gleam, inspired by Scrapling: fetch pages politely, parse HTML or XML, find what you want with CSS selectors, and read it out. The API will change before 1.0.
gleam add scream
import gleam/list
import scream
import scream/fetch
pub fn main() {
// Say who you are: sites rate limit and block anonymous clients first.
let fetcher = fetch.new("my-research-bot/1.0 (+https://example.com/bot)")
// Feeds are XML. The fetcher waits between requests and backs off on 429.
let assert Ok(response) =
fetch.get(fetcher, "https://example.com/feed.atom")
let assert Ok(feed) = scream.parse_xml(response.body)
let assert Ok(titles) = scream.select(scream.root(feed), "entry > title")
list.map(titles, scream.text)
}
scream.parse/scream.parse_xmlturn a string into aDocument.scream.select,select_oneandmatchestake CSS selectors: types,#id,.class, attribute selectors, the four combinators,,groups,:first-child,:last-child,:nth-child()and:not().root,parent,children,next_sibling,previous_sibling,ancestorsanddescendantsmove around the tree;tag,attribute,attributes,textandown_textread from it.scream/fetchmakes GET requests with your User-Agent and headers, a delay between requests, and retries that honorRetry-After. For JSON APIs, decoderesponse.bodywithgleam_json.
Further documentation can be found at https://scream.hexdocs.pm/.
Development #
scream runs on the Erlang target. Its HTML parser, htmerl, is built with rebar3, so have rebar3 on your PATH.
gleam test # Run the tests