I'm working on a web scrapper that has two classes. One takes the data and the other class processes it. The end result of the first class is a list of elements such as results = [1, 2, 3, 4, 5, ...] . The problem is sometimes, due to server-side error, the list can come out empty. How can I loop through this to restart the process until the list is not empty?
I kinda solved it like this. But I'm not sure if this is efficient or a good practice.
class DataScrapper:
def __init__(self):
...
def getData(self):
self.results = []
while not self.results:
...
return self.results
Is this a pythonic way of solving the problem? Is there another more efficient way? Thank you very much.
...is a server side call this may get you blacklisted due to too many requests to the server. You may be better off accepting the empty list and give that as a return - or raise an exception.