1
2
3
### Install libgcc on Alpine Docker Images Source: https://github.com/mischov/meeseeks/blob/main/guides/deployment.md Install the libgcc package on Alpine-based Docker images. This is required for the release stage if your Dockerfile separates build and release stages. ```dockerfile RUN apk add --no-cache libgcc ``` -------------------------------- ### Define a Custom Comment Selector Source: https://github.com/mischov/meeseeks/blob/main/guides/custom_selectors.md Implement `Meeseeks.Selector` to create a custom selector that matches comments containing specific text. This example defines `CommentContainsSelector` which checks if a comment's content includes a given value. ```elixir defmodule CommentContainsSelector do use Meeseeks.Selector alias Meeseeks.Document defstruct value: "" def match(selector, %Document.Comment{} = node, _document, _context) do String.contains?(node.content, selector.value) end def match(_selector, _node, _document, _context) do false end end selector = %CommentContainsSelector{value: "TODO"} Meeseeks.one("", selector) #=> #Meeseeks.Result<{ }> ``` -------------------------------- ### Extracting Element Attributes Source: https://github.com/mischov/meeseeks/blob/main/guides/xpath_selectors.md Use the `attr` extractor to get an element's attribute value, such as its class. ```elixir Meeseeks.all(doc, xpath("//p[@class]")) |> Enum.map(&Meeseeks.attr(&1, "class")) ``` -------------------------------- ### Select Node with CSS Source: https://github.com/mischov/meeseeks/blob/main/README.md Selects the first node matching a CSS selector within a document. Ensure Meeseeks.CSS is imported. ```elixir import Meeseeks.CSS result = Meeseeks.one(document, css("#main p")) #=> #Meeseeks.Result<{
1
}> ``` -------------------------------- ### Select Node with XPath Source: https://github.com/mischov/meeseeks/blob/main/README.md Selects the first node matching an XPath query within a document. Ensure Meeseeks.XPath is imported. ```elixir import Meeseeks.XPath result = Meeseeks.one(document, xpath("//*[@id='main']//p")) #=> #Meeseeks.Result<{1
}> ``` -------------------------------- ### Add Rust Buildpack and Configure Heroku Source: https://github.com/mischov/meeseeks/blob/main/guides/deployment.md Add a Rust buildpack to your Heroku app and set the RUST_SKIP_BUILD environment variable. This ensures Rust is available and configured correctly before the Elixir build. ```bash heroku buildpacks:add -i 1 https://github.com/emk/heroku-buildpack-rust.git echo "RUST_SKIP_BUILD=1" > RustConfig ``` -------------------------------- ### Adding Meeseeks Dependency to Mix Project Source: https://github.com/mischov/meeseeks/blob/main/README.md This code snippet shows how to add the Meeseeks library as a dependency in your Elixir project's `mix.exs` file. After adding this, run `mix deps.get` to fetch the dependency. ```elixir defp deps do [ {:meeseeks, "~> 0.18.0"} ] end ``` -------------------------------- ### Extracting Data from HTML with CSS Selectors Source: https://github.com/mischov/meeseeks/blob/main/README.md This snippet demonstrates how to fetch HTML content and extract specific data points like titles and URLs using Meeseeks with CSS selectors. It requires the HTTPoison library for fetching web content. ```elixir import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do title = Meeseeks.one(story, css(".title a")) %{ title: Meeseeks.text(title), url: Meeseeks.attr(title, "href") } end #=> [%{title: "...", url: "..."}, %{title: "...", url: "..."}, ...] ``` -------------------------------- ### Parse HTML to Document Source: https://github.com/mischov/meeseeks/blob/main/README.md Parses an HTML string into a Meeseeks.Document for querying. Parsing ahead of time is recommended for multiple selections on the same document. ```elixir document = Meeseeks.parse("1
2
3
1
2
3