简体   繁体   中英

Python BeautifulSoup TypeError: find() takes no keyword arguments

I have following

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

I am trying to export all li classes, but the n1 part is changing to n2,n3... n100 Tried to do it this way:

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)

But I am getting the error message: TypeError: find() takes no keyword arguments

any suggestion on how to loop through the above class, to export all elements, till x reaches 100.

youre calling built-in function find and not soup. you need to do:

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

to find them all try use findAll without a loop:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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