Explain what "limit" means?
P粉258788831
2023-08-13 14:47:01
<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>
@boris-verkhovskiy is correct. According to Documentation: "It tells Beautiful Soup to stop collecting after a certain number of results are found."