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
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project.
Baby step #1 is extracting the number ...
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
Sometimes I want to check if the input into a function is not a blank string.
My first approach:
defmodule Example do
def do_stuff(s...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
I would like to know what is the best IDE for elixir development?
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
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








