https://kotlinlang.org logo
#skrape-it
Title
# skrape-it
r

Roger Kreienbühl

08/08/2022, 2:53 PM
Hi I am new to skrape.it and try to extract content of a table. Is there a way to process every table by it self, so I get a List with all texts of a row in a List with all rows? e.g.:
List<List<String>>
One row looks like this:
Copy code
<tr role="row">
    <td class="grad" style="background:#067A25; width:50px">
        <div class="grad_outer">
            <span>4c</span>
        </div>
    </td>
    <td class="name">
        King Louie
    </td>
    <td>
        Dave
    </td>
    <td>
        11.03.2022
    </td>
    <td>
        12
    </td>
    <td>
        64.2
    </td>
</tr>
I also need to extract the background css attribute. How can I do this?
c

Christian Dräger

08/08/2022, 5:05 PM
Hey, I will provide a little example snippet later this evening. It is definitely possibly :)
r

Roger Kreienbühl

08/08/2022, 9:20 PM
Thanks, that would be great.
c

Christian Dräger

08/09/2022, 12:38 PM
sorry for late response. i hope i got it correct. assuming a html contaning a table like this:
Copy code
<div>
            <table>
                <tr>
                    <td>
                        <div>
                            <span>AAA</span>
                        </div>
                    </td>
                    <td class="name">
                        BBB
                    </td>
                    <td>
                        01.01.1970
                    </td>
                    <td>
                        42
                    </td>
                </tr>
                <tr>
                    <td>
                        <div>
                            <span>YYY</span>
                        </div>
                    </td>
                    <td class="name">
                        ZZZ
                    </td>
                    <td>
                        08.08.2022
                    </td>
                    <td>
                        4711
                    </td>
                </tr>
            </table>
        </div>
you want to have a list of every row. a row should be presented by a list of strings. i would probably come up with something like this:
Copy code
...
htmlDocument(someHtmlSnippet) {
            tr {
                findAll {
                    map { <http://it.td|it.td> {
                            findAll { eachText }
                        }
                    }
                }
            }
        }
...
it would return [[AAA, BBB, 01.01.1970, 42], [YYY, ZZZ, 08.08.2022, 4711]]
r

Roger Kreienbühl

08/09/2022, 12:48 PM
Thanks a lot, will try at the evening.
I have tried it and this works just as it should. I forgot to use
<http://it.td|it.td> { ... }
and only did
td { ... }
inside the
map
. This way it gave me a
List<String>
instead of a
List<List<String>>
. Thanks a lot.
47 Views