繁体   English   中英

Python BeautifulSoup TypeError: find() 没有关键字 arguments

[英]Python BeautifulSoup TypeError: find() takes no keyword arguments

我有以下

li class = 'EntityList-item EntityList-item--Regular EntityList-item--n1 bp-radix__faux-anchor'

我正在尝试导出所有 li 类,但 n1 部分正在更改为 n2,n3... n100 尝试这样做:

url = 'https://www.xxxx.com' # just a random website
result = requests.get(url).text
doc = BeautifulSoup(result, 'html.parser')    
doc


x = 1
for add in doc:
    add.find('li', class_ = f'EntityList-item EntityList-item--Regular EntityList-item--n{x} bp-radix__faux-anchor')
    x += 1
    print(add)

但我收到错误消息:TypeError: find() 没有关键字 arguments

关于如何遍历上述 class 以导出所有元素的任何建议,直到 x 达到 100。

您正在调用内置 function 查找而不是汤。 你需要做:

soup.find('li', class_ = f'EntityList-item EntityList-item--Regular EntityList-item--n{x} bp-radix__faux-anchor')

要找到它们,请尝试在没有循环的情况下使用 findAll:

soup.findAll('li', class_ = f'EntityList-item EntityList-item--Regular EntityList-item--n{x} bp-radix__faux-anchor')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM