[Python] Why won't BeautifulSoup's find_all find the li elements of a certain class?

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to scrape the LinkedIn job page and would like to isolate the job cards. However, whenever I try using find_all with a specific class for the job card, it gives me an empty list. Here's my code:

    import requests

    html_text = requests.get('https://www.linkedin.com/jobs/search-results/?keywords=recent%20graduate%20data').text
    soup = BeautifulSoup(html_text, 'lxml')
    jobs = soup.find_all('li', class_ = {'ember-view', 'semantic-search-results-list__list-item', 'occludable-update', 'p0', 'relative', "scaffold-layout__list-item"})
    print(jobs) # gives []


    The class used to have a lot of extra whitespace, but I saw on a different post that it's better to separate the class name into a list instead of leaving it as a long string ("ember-view semantic-search-results-list__list-item occludable-update p0 relative scaffold-layout__list-item ").

    Has anyone run into this problem?

    Continue reading...

Compartilhe esta Página