解释一下'limit”的含义是什么?
P粉258788831
P粉258788831 2023-08-13 14:47:01
0
1
582
<p><br /></p> <pre class="brush:py;toolbar:false;">import urllib.request, urllib.parse, urllib.error import collections collections.Callable = collections.abc.Callable from bs4 import BeautifulSoup import ssl # 忽略SSL证书错误 ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE url = input('输入URL:') count = input('输入次数:') position = input('输入位置:') print('正在获取:', url) for i in range(0,int(count)): html = urllib.request.urlopen(url, context=ctx).read() soup = BeautifulSoup(html, 'html.parser') # 获取标签 tags = soup('a',limit=int(position)) for tag in tags: url = tag.get('href',None) print('正在获取:', tag.get('href',None)) </pre> <p>在这段代码中,请解释一下<code>limit</code>函数的作用是什么?</p> <p>我删除了limit后得到了完全不同的结果。</p>
P粉258788831
P粉258788831

全部回复(1)
P粉063039990

@boris-verkhovskiy 是正确的。根据文档: "它告诉Beautiful Soup在找到一定数量的结果后停止收集。"

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!