I use python with selenium try to scrape job position information from multiple pages but so far only first element information being printed out.
Another difficulty is that the website I am scraping is a job portal for UN, which means it also got information from other UN websites. If I want to get the orginal link, I have to click one position ,then click "allpy now", then redirect to the UN original website.
Thank you so much for reading my questions, I am a foregin policy backgroud person,just started my web scraping learning.
#import required packages
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
#define the driver variable
driver = webdriver.Chrome()
#navigate to url given
driver.get("https://www.unjobnet.org/jobs?driver.get("https://www.unjobnet.org/jobs?orgtypes%5B0%5D=United+Nations+System&apptypes%5B0%5D=Internship&keywords=&orderby=closing")
#wait 5 seconds for elements to load
time.sleep(5)
#locate elements based on specified css path
divs = driver.find_elements(By.XPATH,'//*[@id="main"]/div[2]')
#get the text attribute of each element and print it
for div in divs:
title = div.find_element(By.XPATH,'//*[@id="main"]/div[2]/div/div[1]/div/div[2]/div[1]').text
area = div.find_element(By.XPATH,'//*[@id="main"]/div[2]/div/div[1]/div/div[2]/div[2]').text
place = div.find_element(By.XPATH,'//*[@id="main"]/div[2]/div/div[1]/div/div[2]/div[4]').text
deadline = div.find_element(By.XPATH,'//*[@id="main"]/div[2]/div/div[1]/div/div[2]/div[7]/span[2]').text
print(title, area, place, deadline)
print result:
Communications - Intern UNDP - United Nations Development Programme New Delhi (India) Closing soon: 19 Jul 2023