Answer the question
In order to leave comments, you need to log in
How to use Selenium to grab only some elements from a tag?
There is a certain page on which there is a certain table in which the information I need is presented approximately as follows:
<tbody>
<tr>
<td>День</td>
<td>Время</td>
<td>Кабинет</td>
<td>Преподаватель</td>
<td>Дисциплина</td>
<td>Вид</td>
<td>Ссылка</td>
</tr>
<tr>
<td>День</td>
<td>Время</td>
<td>Кабинет</td>
<td>Преподаватель</td>
<td>Дисциплина</td>
<td>Вид</td>
<td>Ссылка</td>
</tr>
. . .
</tbody>
array = [["Время", "Преподаватель", "Дисциплина", "Ссылка"],
["Время", "Преподаватель", "Дисциплина", "Ссылка"],
. . .]
Answer the question
In order to leave comments, you need to log in
Well, just specify the correct xpath:
import io
from lxml import etree
parser = etree.HTMLParser()
data = """<tbody>
<tr>
<td>День</td>
<td>Время</td>
<td>Кабинет</td>
<td>Преподаватель</td>
<td>Дисциплина</td>
<td>Вид</td>
<td>Ссылка</td>
</tr>
<tr>
<td>День</td>
<td>Время</td>
<td>Кабинет</td>
<td>Преподаватель</td>
<td>Дисциплина</td>
<td>Вид</td>
<td>Ссылка</td>
</tr>
</tbody>"""
root = etree.parse(io.StringIO(data), parser=parser)
[[x.xpath('.//td[2]')[0].text, x.xpath('.//td[4]')[0].text] for x in root.xpath('.//tr')]
# [['Время', 'Преподаватель'], ['Время', 'Преподаватель']]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question