Skip to content

Instantly share code, notes, and snippets.

@antedeguemon
Last active September 29, 2021 21:43
Show Gist options
  • Save antedeguemon/4c67f6882bf5250ea6db9aeca10ea048 to your computer and use it in GitHub Desktop.
Save antedeguemon/4c67f6882bf5250ea6db9aeca10ea048 to your computer and use it in GitHub Desktop.
Floki selectors snippets

Floki snippets

A collection of snippets for finding HTML elements using Floki.

Under construction.

Find the n-th element

html = """
  <div>
    <span>First element</span>
    <span>Second element</span>
    <span>Third element</span>
    <span>Fourth element</span>
  </div>
"""

parsed_html = Floki.parse_document!(html) 

[first_element] = Floki.find(parsed_html, "span:first-of-type") 
[third_element] = Floki.find(parsed_html, "span:nth-of-type(3)") 
[fourth_element] = Floki.find(parsed_html, "span:last-of-type") 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment