From the code below as you can see mysearch is called without arguments. How is this function call possible? How is it this technique called? Where does the method get it's argument (tag)? I'm sorry I can't find my answer anywhere...
def myserach(tag):
return tag.has_attr('ResultsAd') # and tag['li']
with open('index.html', 'rb') as file:
soup = BeautifulSoup(file, "html.parser")
elements1 = soup.find_all('div', attrs={"class": "ResultsAd"})
elements1 = soup.find_all(myserach)
The function is not called in your code snippet.
May be this example helps you understand better.
def foo(str):
print(str)
def bar(arg):
arg("now calling foo")
bar(foo)
It's not "calling a function", it's passing a function name (a function poiter in C terma) as argument to another function that later will call it with appropriate number of parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With