Why i can't get the job posted while scraping in glints.com

I want to get the job posting element that is inside the job item in glints.com but strangely it can't, even though for classname is the same, i don't know why it can't to get it. However, in outside the item job it can i get it.

maybe someone understand about it. Thank you.

this is for the code

tags = soup.find_all('div', class_=re.compile(r'JobCardsc__JobcardContainer-sc-1f9hdu8-0 RBKNv CompactOpportunityCardsc__CompactJobCardWrapper-sc-1y4v110-0 cqpitP compact_job_card'))

for tag in tags:
  def get_link(tag):
    link = tag.find('div', class_=re.compile('JobCardsc__JobCardWrapper-sc-1f9hdu8-1 elhnMG')).find('a', class_=re.compile('CompactOpportunityCardsc__CardAnchorWrapper-sc-1y4v110-18 fKmNmg job-search-results_job-card_link')).get('href')
    link = 'https://glints.com'+link
    return link

  link_res = requests.get(get_link(tag))
  link_soup = BeautifulSoup(link_res.text, 'lxml')
  container = link_soup.find('main',class_=re.compile('Opportunitysc__Main-sc-1gsvee3-3 cOQpRQ'))
  
  job_name_tag = container.find('div', class_=re.compile('TopFoldsc__JobOverViewContainer-kklg8i-2 hCbpbU'))
  if job_name_tag is not None:
    job_name = job_name_tag.find('h1', class_=re.compile('TopFoldsc__JobOverViewTitle-kklg8i-3 gaBsxq')).text.strip()
  else:
    job_name = 'None'

#this is for the element job posted in inside the job item
  tag_posted = container.find('div', class_=re.compile('TopFoldsc__JobOverViewInfoContainer-kklg8i-8 cyqTAm')).find('div', class_=re.compile('TopFoldsc__JobOverViewTime-kklg8i-10 iDOZMJ'))
  job_posted = tag_posted.find('span',class_=re.compile('TopFoldsc__UpdatedAt-kklg8i-12 fSjRSR'))
  if job_posted:
      job_posted = job_posted.text
  else:
     job_posted = 'None'

#this is for the element job posted in outside the job item
  tag_post = tag.find('div', class_=re.compile('CompactOpportunityCardsc__OpportunityMeta-sc-1y4v110-14 eSReDz'))
  job_post = tag_post.find('span',class_=re.compile('CompactOpportunityCardsc__UpdatedAtMessage-sc-1y4v110-17 hrxARV'))
  if job_post is not None:
    job_post = job_post.text
  else:
    job_post = 'None'
  
  data = [job_name,job_posted, job_post]
  print(data)

1 answer

  • answered 2022-05-05 09:17 Martin Evans

    The classes you are searching for probably change with each call. As you are compiling each name, I suggest you simplify the names as much as possible. For example:

    from bs4 import BeautifulSoup
    import requests
    import csv
    import re
    
    req = requests.get("https://glints.com/opportunities/jobs/explore?keyword=software&country=SG&searchCity=127215&locationName=Singapore")
    soup = BeautifulSoup(req.content, 'lxml')
    tags = soup.find_all('div', class_=re.compile(r'JobCardsc__JobcardContainer'))
    
    for tag in tags:
      
      def get_link(tag):
        link = tag.find('div', class_=re.compile('JobCardsc__JobCardWrapper')).find('a', class_=re.compile('CompactOpportunityCardsc__CardAnchorWrapper')).get('href')
        link = 'https://glints.com'+link
        return link
    
      link_res = requests.get(get_link(tag))
      link_soup = BeautifulSoup(link_res.text, 'lxml')
      
      container = link_soup.find('main',class_=re.compile('Opportunitysc__Main'))
      
      job_name_tag = container.find('div', class_=re.compile('JobOverViewContainer'))
      if job_name_tag is not None:
        job_name = job_name_tag.find('h1', class_=re.compile('JobOverViewTitle')).text.strip()
      else:
        job_name = 'None'
    
    #this is for the element job posted in inside the job item
      tag_posted = container.find('div', class_=re.compile('JobOverViewInfoContainer')).find('div', class_=re.compile('JobOverView'))
      job_posted = tag_posted.find('span',class_=re.compile('TopFoldsc'))
    
      if job_posted:
         job_posted = job_posted.text
      else:
         job_posted = 'None'
    
    #this is for the element job posted in outside the job item
      tag_post = tag.find('div', class_=re.compile('CompactOpportunityCardsc'))
      job_post = tag_post.find('span', class_=re.compile('CompactOpportunityCardsc'))
      
      if job_post is not None:
        job_post = job_post.text
      else:
        job_post = 'None'
      
      data = [job_name, job_posted, job_post]
      print(data)            
    

    This search gave results starting:

    ['Software Architect', 'None', 'PSA International Pte Ltd']
    ['Software Engineer (Logistics)', 'SGD10,000 - 14,000/month', 'Confidential Company']
    ['Software Developer', 'SGD3,500 - 6,000/month', 'ANOTECH Singapore']
    ['Software Engineer', 'SGD2,000 - 3,500/month', 'Presidium Instruments Pte Ltd']
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum