S
S
semen79072017-04-17 16:55:18
Python
semen7907, 2017-04-17 16:55:18

How to get data from classes? python xpath?

Hello everyone, there is such a question, there are many identical "data-song" classes in the code below, I only get data from the first "data-song"
How can I get subsequent data-songs, let's say the first 5 or how can I get only the second one, or only the third? etc.

g.doc.select('//script[@class="data-song"]').text()

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2017-04-17
@semen7907

1) get everything in the list
2) choose the second one from the list

S
screen_sailor, 2017-04-17
@screen_sailor

And if so?
g.doc.select('//script[@class="data-song"][2]').text() - select only the second one,
g.doc.select('//script[@class="data -song"][position()<6]').text() - select the first five.

I
Igor Lyutoev, 2017-04-19
@loader777

Something like this:

for item in g.doc.select('//script[@class="data-song"]'):
    print(item.text())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question