在帖子链接的示例中有关python抓取的问题

时间:2020-05-27 18:27:55

标签: python

我正在查看此示例-Can someone explain me in detail how this code works regarding (Using Python to Access Web Data),并且对代码中count = 0的最后一行之一有疑问

任何人都可以解释为什么需要它吗?如果可能,@ chitown88是否可以帮助您参与此线程?

if count == position:  #<------- and the variable to get the position
         url  = tag.get('href', None)
         print("Retrieving:" , url)
         count = 0  <----------------------------------------this line
         break

谢谢

1 个答案:

答案 0 :(得分:1)

...
count = 0 # <-- Must reset this value.
...

while n < numbers:
    ...
    for tag in tags:
      ...
      if count == position:
         ...
         count = 0 # <-- Resetting this value before the next for-loop.
         break # <-- This breaks out of the for-loop, going back into the while-loop