Home  >  Q&A  >  body text

Explain what "limit" means?

<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 # Ignore SSL certificate errors ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE url = input('Enter URL:') count = input('Number of inputs: ') position = input('Input position: ') print('Getting:', url) for i in range(0,int(count)): html = urllib.request.urlopen(url, context=ctx).read() soup = BeautifulSoup(html, 'html.parser') # Get tags tags = soup('a',limit=int(position)) for tag in tags: url = tag.get('href',None) print('Getting:', tag.get('href',None)) </pre> <p>In this code, please explain what the <code>limit</code> function does? </p> <p>I got completely different results after deleting the limit. </p>
P粉258788831P粉258788831433 days ago605

reply all(1)I'll reply

  • P粉063039990

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

    @boris-verkhovskiy is correct. According to Documentation: "It tells Beautiful Soup to stop collecting after a certain number of results are found."

    reply
    0
  • Cancelreply