Answer the question
In order to leave comments, you need to log in
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
1) get everything in the list
2) choose the second one from the list
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.
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 questionAsk a Question
731 491 924 answers to any question