Search code examples
pythonhtmlbeautifulsouphtml-parsing

How to limit the result of select tag in beautifulsoup?


For example, I have this:

result = soup.select('div#test > div.filters > span.text')

I want to limit the result of the above list to 10 items.

In case of find_all() one can use the limit argument but what about select()?


Solution

  • There is no limit argument for select(), but you can slice the resultset:

    soup.select('div#test > div.filters > span.text')[:10]