Home > Blockchain >  Python BeautifulSoup TypeError: find() takes no keyword arguments
Python BeautifulSoup TypeError: find() takes no keyword arguments

Time:01-19

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.

CodePudding user response:

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')

i found your problem:

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

for i in range(101):
    print(soup.find('li', class_ = f'EntityList-item EntityList-item--Regular EntityList-item--n{i} bp-radix__faux-anchor'))
  •  Tags:  
  • Related