首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >文章中链接的示例中有关python抓取的问题

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

Stack Overflow用户
提问于 2020-05-27 18:27:55
回答 1查看 35关注 0票数 1

我回顾了这个例子-Can someone explain me in detail how this code works regarding (Using Python to Access Web Data),并对代码中的最后一行提出了一个问题,其中count =0

有人能解释一下为什么要在那里吗?如果可能的话,@chitown88 88,您能帮上忙吗?

代码语言:javascript
运行
复制
if count == position:  #<------- and the variable to get the position
         url  = tag.get('href', None)
         print("Retrieving:" , url)
         count = 0  <----------------------------------------this line
         break

谢谢,

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-27 18:34:28

代码语言:javascript
运行
复制
...
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62050303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档