bb和cc在下面的代码中相等,为什么会这样?汤是一个对象,为什么它可以在此处接受另一个参数“ a”?在此,汤('a')是函数调用还是其他类/对象初始化?如果是函数调用,则在类中没有找到call定义。我希望问题清楚。谢谢。
from bs4 import BeautifulSoup
soup = BeautifulSoup("<html><a href='bla'>sss</a><a>cc</a></html>", 'html.parser')
bb = soup('a')
cc = soup.find_all('a')
嗯,实际上没有什么区别,将tag
称为alias
的findAll
def __call__(self, *args, **kwargs):
"""Calling a tag like a function is the same as calling its
find_all() method. Eg. tag('a') returns a list of all the A tags
found within this tag."""
return self.find_all(*args, **kwargs)