0
0
0x70002018-10-12 17:06:03
Python
0x7000, 2018-10-12 17:06:03

How to get data from cells?

How it is possible to pull out values ​​- 1,2,3 from the table "Journal"? I did not find a suitable library. There is a table like:

<table id="journal" class="marks">
<tbody>
<tr>'
<td class="s2">
<strong class="u">HTML</strong>
</td>
<td class="tac">
<span class="mark mY analytics-app-popup-mark" data-num="0">1</span>
<span class="mark mY analytics-app-popup-mark" data-num="0">2</span>
<span class="mark mG analytics-app-popup-mark" data-num="0">3</span>
</td>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Lisin, 2018-10-16
@BlackLacost

from lxml import etree

html = """
<table id="journal" class="marks">
    <tbody>
        <tr>
            <td class="s2">
                <strong class="u">HTML</strong>
            </td>
            <td class="tac">
                <span class="mark mY analytics-app-popup-mark" data-num="0">1</span>
                <span class="mark mY analytics-app-popup-mark" data-num="0">2</span>
                <span class="mark mG analytics-app-popup-mark" data-num="0">3</span>
            </td>
        </tr>
    </tbody>
</table>"""

tree = etree.fromstring(html)

for block in tree.xpath("//table[@id='journal']/descendant::span[starts-with(@class, 'mark')]"):
    print(block.xpath("text()"))

['1']
['2']
['3']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question