TrailingDots
Floki attribute with space not selected
In attempting to parse a html table, I ran across a class that I cannot figure out how to parse. Specifically:
defmodule Embedded do
@doc """
Floki can parse class selectors with embedded spaces?
"""
def embedded() do
html = """
<tr class="team">
<td class="name">
Boston Bruins
</td>
<td class="ot-losses">
</td>
<td class="diff text-success">
35
</td>
</tr>
"""
{:ok, parsed} = Floki.parse_document(html)
IO.puts("parsed=\n#{inspect(parsed)}")
parsed_td = Floki.find(parsed, "td")
IO.puts("\nparsed_td=#{inspect(parsed_td)}")
tds = Floki.find(parsed, "td") |> Floki.attribute("class")
IO.puts("tds=#{inspect(tds)}")
# tds=["\nname", "ot-losses", "diff text-success"]
name = Floki.find(parsed, "td.name") |> Floki.text()
IO.puts("\nname=#{inspect(name)}")
# name="\n Boston Bruins\n "
ot_losses = Floki.find(parsed, "td.ot_losses") |> Floki.text()
IO.puts("\not_losses=#{inspect(ot_losses)}")
# name="\n Boston Bruins\n "
# FAILS: html clearly shows a value of 35
diff = Floki.find(parsed, "td.diff text-success") |> Floki.text()
IO.puts("\ndiff=#{inspect(diff)}")
# diff=
end
end
The name and ot-losses get selected ok.
What Floki function I pull out the text for the "diff text-success?
This Floki function should work all other classes in the table.
I have no control over the html - it was read from a website.
The html fragment is presented straight from the source page.
Most Liked
mindok
Hi @TrailingDots,
You aren’t selecting on a class name with a space in it, you are wanting to select on two classes. Try td.diff.text-success as your selector rather than td.diff text-success
3
Popular in Questions
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
How to handle excepions in elixir?
Suppose i have A, B, C ,D, E modules. and each module has get() function.
A.get() method will call t...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
I would like to know what is the best IDE for elixir development?
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Other popular topics
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








