I'm trying to go through a website one page at a time, clicking on the element next
, which in the HTML code is class="pg-next"
. Eventually, though, I'm going to get to the end, and there won't be a next
element anymore, at which point I'd like to stop the loop. I have something like this:
pg_next_exists = True
while pg_next_exists:
#
# carry out necessary actions
#
if ...: # if the pg-next element can be found
pass
else:
pg_next_exists = False # at which point the while loop stops
How do I check if that element still exists?