I am trying to obtain the links of the job offers on a website, I have managed to obtain the title of the position and the company but I cannot extract the link of the offer.
The source of the data is: https://www.jobs.ch/en/vacancies/?term=Data%20Analyst
import requests
from bs4 import BeautifulSoup as bs
url = 'https://www.jobs.ch/en/vacancies/?term=Data%20Analyst'
page = requests.get(url)
soup = bs(page.content, "html.parser")
results = soup.find(class_="Div-sc-1cpunnt-0 ujqkk")
job_elements = results.find_all("a", class_="Link__ExtendedRR6Link-sc-czsz28-1 jzwvjr Link-sc-czsz28-2 VacancyLink___StyledLink-sc-ufp08j-0 bzpUGN zoplL")
for job_element in job_elements:
title_element = job_element.find("span", class_="Span-sc-1ybanni-0 Text__span-sc-1lu7urs-12 Text-sc-1lu7urs-13 VacancySerpItem___StyledText-sc-ppntto-4 jpKTRn bbefum hSicAH")
company_element = job_element.find("p", class_="P-sc-hyu5hk-0 Text__p2-sc-1lu7urs-10 Span-sc-1ybanni-0 Text__span-sc-1lu7urs-12 Text-sc-1lu7urs-13 cHnalP cTUsVs")
print(title_element.text)
print(company_element.text)
print()
# Until here everything works !
Now I want to be able to get the links of each job offer.
I have tried with this code:
for job_element in job_elements:
link = job_element.find('a', attrs={'class':'Link__ExtendedRR6Link-sc-czsz28-1 jzwvjr Link-sc-czsz28-2 VacancyLink___StyledLink-sc-ufp08j-0 bzpUGN zoplL'})
print(link.get('href'))
I get this message:
AttributeError Traceback (most recent call last)
c:\Users\leant\OneDrive\Documentos\Jupyter\WebScrapping\Youtube\program01.ipynb Cell 8 in <cell line: 1>()
2 link = job_element.find('a', attrs={'class':'Link__ExtendedRR6Link-sc-czsz28-1 jzwvjr Link-sc-czsz28-2 VacancyLink___StyledLink-sc-ufp08j-0 bzpUGN zoplL'})
3 #print(title_element.text)
4 #print(company_element.text)
----> 5 print(link.get('href'))
AttributeError: 'NoneType' object has no attribute 'get'
I have tried too this:
for job_element in job_elements:
link = job_element.find('a', class_='Link__ExtendedRR6Link-sc-czsz28-1 jzwvjr Link-sc-czsz28-2 VacancyLink___StyledLink-sc-ufp08j-0 bzpUGN zoplL')
print(link.get('href'))
But I get the same result, I can't find the error. Here is a piece of the html code of the site:
<a class="Link__ExtendedRR6Link-sc-czsz28-1 jzwvjr Link-sc-czsz28-2 VacancyLink___StyledLink-sc-ufp08j-0 bzpUGN zoplL" data-cy="job-link" data-event-type="internal_link" href="/en/vacancies/detail/c82b50d0-cccb-42af-88a3-8cb9e79a88a6/?source=vacancy_search" tabindex="0" title="Data Analyst / Anwendungsentwickler*in">
Thank you very much for your contributions!