Q:

Problem with scraping and saving data using Xpath and Selenium

So Im trying to scrape information about rate, level, duration, certification and save them in csv file. First of all, I don't know if I'm doing it right because I am totally new in Selenium and I don't have idea how to save it correctly in one csv file. All information comes from this site: here is the link. I was trying to use below code but it didn't work:
driver=webdriver.Firefox(executable_path="/usr/bin/geckodriver")

driver.get('https://alison.com/course/global-islamic-finance-and-banking')

rate = driver.find_element(By.XPATH, '//div[contains(@class,"course-banner")]//li[2]//div[2]')

level = driver.find_element(By.XPATH, '//span[contains(text(),"Academic - Third Level - Level 1")]')

duration = driver.find_element(By.XPATH, '//div[contains(@class,"course-brief-container")]//div[contains(@class,"course-brief")]//li[1]//div[2]')

certification = driver.find_element(By.XPATH, '//div[contains(@class,"course-brief-container")]//div[contains(@class,"course-brief")]//li[3]//div[2]')

I want to scrap these data and save at the csv file. 
Do you have any idea how to scrap this thing? Thank you for your help.

A:

You need to put exact xpath of the element from which you are trying to extract the text. In you code xpath are not exact to the target element. You can try as below.
Note that rate value is combined text and you will have to remove Rated text from it.
driver.get("https://alison.com/course/global-islamic-finance-and-banking")
driver.maximize_window()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//ul[@class='course-banner--info']/li[2]/div[2]/h4")))
rate =  driver.find_element(By.XPATH, "//ul[@class='course-banner--info']/li[2]/div[2]/h4").text
level = driver.find_element(By.XPATH, "//ul[@class='course-banner--info']/li[3]/a/div[2]/span").text
duration = driver.find_element(By.XPATH, "//li[@class='course-icons']/div[2]/h3[contains(text(),'Duration')]/following-sibling::span").text
certification = driver.find_element(By.XPATH, "//li[@class='course-icons']/div[2]/h3[contains(text(),'Certification')]/following-sibling::span").text

print(rate)
print(level)
print(duration)
print(certification)

