Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于文章中链接的示例中的python抓取的问题_Python - Fatal编程技术网

关于文章中链接的示例中的python抓取的问题

关于文章中链接的示例中的python抓取的问题,python,Python,我正在回顾这个示例,对代码中最后一行的计数=0有一个问题 谁能解释一下为什么它需要在那里?如果可能的话,@chitown88你能帮忙吗,因为你参与了这个帖子 if count == position: #<------- and the variable to get the position url = tag.get('href', None) print("Retrieving:" , url) count = 0 <

我正在回顾这个示例,对代码中最后一行的计数=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
如果计数==位置:#
。。。

count=0#由于
count
是在
while
循环之外声明的,因此在中断
for
的内部
循环之前,代码会在
while
循环的下一次迭代中将
count
变量重置为
0
。感谢您的澄清。我理解代码在切换到下一个url后需要重新计数。有道理。