Looping around

The spider.py script contains three loops:

REMEMBER Python programmers generally favor for loops, because for loops can both assign values and provide one element at a time.

Tip A while loop is often better when you are both adding and deleting elements, so we used a while loop in the section where the run() method deletes elements from the self._links_to_process list (via the list method pop()) and also adds elements to the list (via process_page()).

Chapter 10 shows you more ways to use loops.

Was this article helpful?

0 0

Post a comment