Scrape the information of the top 10 jobs
4.1 In this section, we will scrape the elements below:
4.2 Get the job item from the searching result list with parameter index
Python3
# Here we set range(1,11) to get top # 10 jobs, it can be set with any value for i in range ( 1 , 11 ): # Wait the job item appears in 5 second, # and get the element with index value ele = _tab.wait_appear(locator.chrome.linkedin.jobitem.job_listitem, { "index" : i}, wait_timeout = 5 ) |
4.3 Get the title, the company name, the size of the company, the post date, the job type for each job item
Python3
# Initial job item search dict details = {} # Click job item ele.click() # Wait job item's title appears in 5 seconds job_title_ele = _tab.wait_appear( locator.chrome.linkedin.jobitem.job_title, wait_timeout = 5 ) # If job item's title exists, get the title # string and save into result object 'details' if job_title_ele: details[ "Job Title" ] = job_title_ele.get_text().strip() # Wait job item's company name appears in 5 seconds job_company_ele = _tab.wait_appear( locator.chrome.linkedin.jobitem.job_company, wait_timeout = 2 ) # If job item's company name exists, get the company # name string and save into result object 'details' if job_company_ele: details[ "Company Name" ] = job_company_ele.get_text().strip() # Wait job item's company scale appears in 5 seconds company_size_ele = _tab.wait_appear( locator.chrome.linkedin.jobitem.company_size, wait_timeout = 2 ) # If job item's company scale exists, get the # company scale string and save into result # object 'details' if company_size_ele: scale = company_size_ele.get_text().strip( ) if "employees" in company_size_ele.get_text() else "" details[ "Company Size" ] = scale # Wait job item's post date appears in 5 seconds job_post_date_ele = _tab.wait_appear(locator.chrome.linkedin.jobitem.job_post_date, wait_timeout = 2 ) # If job item's post date exists, get # the post date string and save into # result object 'details' if job_post_date_ele: post_date = job_post_date_ele.get_text().strip() \ if "ago" in job_post_date_ele.get_text() else "" details[ "Post Date" ] = post_date # Wait job item's type appears in 5 seconds job_type_ele = _tab.wait_appear(locator.chrome.linkedin.jobitem.job_type, wait_timeout = 2 ) # If job item's type exists, get the type string # and save into result object 'details' if job_type_ele: details[ "Job Type" ] = job_type_ele.get_text().strip() |
4.4 Get job link
4.4.1 Getting clipboard data with pywin32
Python3
# Library for win32 clipboard api import win32clipboard # Get clipboard data def get_clipboard_data(): try : # Call open clipboard api win32clipboard.OpenClipboard() # Call get clipboard data api, and return the data data = win32clipboard.GetClipboardData() return data except : # If it got exception, return empty string return "" finally : # Call close clipboard api win32clipboard.CloseClipboard() |
4.4.2 Click the Share button and Copy link button, then get data from clipboard
Python3
# Wait job item's share button appears # in 5 seconds job_share_btn_ele = _tab.wait_appear( locator.chrome.linkedin.jobitem.share_button, wait_timeout = 2 ) # If job item's share button exists, click # the share button if job_share_btn_ele: job_share_btn_ele.click() # Wait the copy link button appears in 5 seconds copy_link = _tab.wait_appear( locator.chrome.linkedin.jobitem.copy_link, wait_timeout = 2 ) # If the copy link exists, click the copy # link to set clipboard data if copy_link: copy_link.click() # Sleep 0.2 second to wait the clipboard # in ready state sleep( 0.2 ) # Get the job link string and save into # result object 'details' details[ "Job Link" ] = get_clipboard_data() |
Automatically Get Top 10 Jobs from LinkedIn Using Python
Here we are going to use Clicknium to scrape LinkedIn top 10 jobs. First, we will login to LinkedIn to search the jobs according to the job keyword(the title, the skill, or the company) and the location, and then get the top 10 jobs in the search results. For each job, we will get the job information, such as the title, the company name, the size of the company, the post date, the job type, and the link URL. At last, we will save the results into CSV file.
The steps overview are as below:
- Login to LinkedIn
- Search jobs with the keyword and location
- Scrape the information of the top 10 jobs
- Save search results into csv file