Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question