scream

Package Version Hex Docs

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)
}

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
✨ Search Document