首頁  >  問答  >  主體

解釋一下「limit」的意思是什麼?

<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('輸入網址:') 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粉258788831P粉258788831433 天前603

全部回覆(1)我來回復

  • P粉063039990

    P粉0630399902023-08-14 10:58:05

    @boris-verkhovskiy 是正確的。根據文檔: "它告訴Beautiful Soup在找到一定數量的結果後停止收集。"

    回覆
    0
  • 取消回覆