skip to Main Content

I am using the find function to retrieve this object:

<h1 data-testid=“organization-cover-title” class=“sc-1wcv2gl-2 kpUYKd”>Company</h1>

With this code below, it returns a NoneType

company = soup.find(‘h1’, attrs = {‘data-testid’:‘organization-cover-title’, ‘class’:‘sc-1wcv2gl-2 kpUYKd’}).string

It also does not return a string with one or the other attribute.

Would you be so kind as to find a solution?
Thanks

2

Answers


  1. Chosen as BEST ANSWER

    The code was right actually. It works


  2. Your example is using curly quotes in HTML and CODE that are the quotation marks used in good typography.

    You have to use the straight single quote (‘) or the straight double quote (") to get it working in both HTML and CODE.

    from bs4 import BeautifulSoup
    html = '''
    <h1 data-testid="organization-cover-title" class="sc-1wcv2gl-2 kpUYKd">Company</h1>
    '''
    soup = BeautifulSoup(html)
    
    soup.find('h1', attrs = {'data-testid':'organization-cover-title', 'class':'sc-1wcv2gl-2 kpUYKd'}).get_text()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search