N
N
nordwind20132017-12-07 14:45:07
Python
nordwind2013, 2017-12-07 14:45:07

How to limit a Python xpath list?

from lxml import html
import requests
page = requests.get('https://coinmarketcap.com/all/views/all/')
tree = html.fromstring(page.content)
names = tree.xpath('//*[@class="currency-name-container"]/text()')

I put together a list like this using xpath. However, I need to get only the first 150 names, and the list turns out to be 1334. How can I limit such a list?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2017-12-07
@nordwind2013

Doesn't this build work?

names = tree.xpath('//*[@class="currency-name-container"]/text()')[0:150]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question