# How to get value attribute from an \< li \> element of HTML in Julia?

**URL:** <https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010>\
**Category:** Web Stack\
**Tags:** html\
**Created:** [June 30, 2023, 9:52am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010 "2023-06-30T09:52:53Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 30, 2023, 9:52am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/1 "2023-06-30T09:52:53Z")

</div>

I want to get _value_ attribute from all \< li \> element of HTML. Like 34123, 34122 etc, in a array form so that i can use them for identification.

![image](https://global.discourse-cdn.com/julialang/original/3X/1/3/131bc1e5895fa518922a9c27f9a81bb2fe8ff878.png)

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [June 30, 2023, 9:59am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/2 "2023-06-30T09:59:16Z")

</div>

This is related to the Gumbo documentation.

Just writing code that I will not run - so take it with a grain of salt:

```julia
li_elements = children(ol_element)
li_vals = [getattr(li, "value") for li in li_elements]

```

Your `li_vals` should be a vector holding all the values from the li elements at this point.

Please take a look at the convenience methods provided by [Gumbo.jl](https://github.com/JuliaWeb/Gumbo.jl).

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 1, 2023, 8:12am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/3 "2023-07-01T08:12:53Z")

</div>

Please see this i am not able to extract value of \< li \> element. 🙂

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/9/39719da12ac7f8cf55b0aee65117747d2c5db8ef.png)

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [July 1, 2023, 8:27am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/4 "2023-07-01T08:27:22Z")

</div>

In your input line, after `Gumbo.HTMLElement{:li}` you’ve put a colon (`:`), which is usually the start of a range:

```julia
1:10

```

so I’m guessing that the message is saying that you started a range expression, used a colon, but then didn’t supply the last part(s) of the range.

I’d have to read the Gumbo docs to find out whether ranges are OK here.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 1, 2023, 8:31am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/5 "2023-07-01T08:31:32Z")

</div>

MethodError: no method matching (::Colon)(::Type{Gumbo.HTMLElement{:li}}, ::Int64)

Closest candidates are:

(::Colon)(::T, ::Any, !Matched::T) where T

@ Base range.jl:44

(::Colon)(!Matched::T, ::Real, !Matched::T) where T\<:AbstractFloat

@ Base range.jl:18

(::Colon)(!Matched::T, ::T) where T\<:Real

@ Base range.jl:5

…

1. **top-level scope** @_[Local: 1](http://localhost:1234/edit?id=6643073c-16fd-11ee-11bd-0579f4492a99#)_

```julia
getattr(Gumbo.HTMLElement{:li}:5, value)

```

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [July 1, 2023, 9:15am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/6 "2023-07-01T09:15:10Z")

</div>

What are you hoping to do first with the `:` and now with the `:5`? That does not seem to make sense to me, since `:` would indicate a range, but your start of the range is an li-element and not a number. That is exactly what the error message tells you.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 1, 2023, 9:51am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/7 "2023-07-01T09:51:31Z")

</div>

I want to extract value of \< li \> element and put them in array so that i could get a list of circulars [webpages](https://gcn.nasa.gov/circulars).

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [July 1, 2023, 10:45am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/8 "2023-07-01T10:45:54Z")

</div>

Yes you wrote that above, but I was asking specifically about the `:` and later the `:5` those do not make sense. IN principle you are writing something like `please count from li to nothing for the first and “from li to 5” in the second. That does not make sense and is the origin of your error message.

Have you tried the approach mentioned above?

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 1, 2023, 10:57am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/9 "2023-07-01T10:57:55Z")

</div>

> [@kellertuer](#):
>
> Have you tried the approach mentioned above?

I tried but it is giving error. I am stuck and Gumbo documentation is not detailed for my understanding . I want get those values “34128” .

```julia-auto
<li value="34128">

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/8/88850a0bf106af534044ca0c5d9038c004ac9221.png)

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 1, 2023, 11:37am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/10 "2023-07-01T11:37:23Z")

</div>

@raman_kumar,

There are multiple things that are wrong with your code above:

1. As others pointed out - you have a syntax error - mainly, you use `:` in the wrong place. This has nothing to do with Gumbo or a specific library. I’ll not discuss this - as others have already done this.
2. `getattr` cannot be used with a sequence of HTMLElements as input: you need to call `getattr` with an instance of an HTMLElement (not the signature of the element) and an attribute name (wich is a string).

Also - if you can properly share your code with minimal reproducible examples that we can run, you would enable everybody to offer better help.

Please share your code starting with the document parsing and make sure to include the snippet that gives you a hard time (a screenshot is not a good idea).

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 1, 2023, 11:42am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/11 "2023-07-01T11:42:13Z")

</div>

My code looks like 🙂

```julia
using HTTP , Gumbo , Cascadia, DataFrames,ParserCombinator, Profile
mnurl="https://gcn.nasa.gov/circulars"
q=HTTP.get(mnurl)
g=parsehtml(String(q.body))
bd=g.root[2]
dv= eachmatch(Selector(".grid-container.usa-section ol"), bd)
dv[1]
children(dv[1])

```

after that i want get _value_ of each _\< li \>_ element in _children(dv[1])_ output.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [July 1, 2023, 11:44am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/12 "2023-07-01T11:44:00Z")

</div>

This code does not reproduce any error.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 1, 2023, 11:48am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/13 "2023-07-01T11:48:50Z")

</div>

How to get _value_ of each _\< li \>_ element in _children(dv[1])_ output ? I want get those values like “34128” etc .

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 1, 2023, 11:50am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/14 "2023-07-01T11:50:54Z")

</div>

@raman_kumar,

But I answered this right after you posted the original question.

Please see the first answer and compare it with the following code:

```julia
using HTTP , Gumbo , Cascadia, DataFrames,ParserCombinator, Profile
mnurl="https://gcn.nasa.gov/circulars"
q=HTTP.get(mnurl)
g=parsehtml(String(q.body))
bd=g.root[2]
dv= eachmatch(Selector(".grid-container.usa-section ol"), bd)
dv[1]
children(dv[1])

li_elements = children(dv[1])
li_vals = [getattr(li, "value") for li in li_elements]

# li_vals will contain the following values...
# "34128"
# "34127"
# "34126"
# and so on

```

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [July 1, 2023, 11:51am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/15 "2023-07-01T11:51:30Z")

</div>

Why did you not try the code above? If I do

```julia
li_elements = children(dv[1])
li_vals = [getattr(li, "value") for li in li_elements]

```

I get exactly what you asked for and I only had to rename the variable containing the parent.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 1, 2023, 11:57am UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/16 "2023-07-01T11:57:03Z")

</div>

Thank You both. It is giving circular numbers on first page. can i get the list of all circulars on that [GCN website](https://gcn.nasa.gov/circulars) ?

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 1, 2023, 12:05pm UTC](https://discourse.julialang.org/t/how-to-get-value-attribute-from-an-li-element-of-html-in-julia/101010/17 "2023-07-01T12:05:27Z")

</div>

The answer would be most likely _yes, you can_.

However, to answer in detail, it would require those willing to help to go and inspect the site map and review various HTML sources.

I think the best way to get help is to try and create specific posts with a narrow enough issue - and always try to provide enough context + code (if the case).
