D
D
Danil Neskazhu2020-07-20 06:33:41
Python
Danil Neskazhu, 2020-07-20 06:33:41

How to parse the first 5 occurrences using BS4?

Good day.
Faced such a task that when parsing (Beautiful Soup) it is necessary to take only the first 5 occurrences for a certain tag. It's just that the find method in the loop takes the same page element 5 times. Find all is executed immediately, and I didn’t manage to put a counter on it up to 5 and then make a break.
Are there any other ways in this library to take only the number of occurrences you need for a tag?
I know, you can take everything, and then just cut the first 5 results. But the process of parsing with findall on the desired site takes a lot of time, and I want to speed up the parsing script and remove a dozen lines of code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zexer, 2020-07-20
@dannight0151

There seems to be something similar to your question here
https://stackoverflow.com/questions/8724352/gettin...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question