URGENT ! I have a problem in my code. Please Help!!

0 votes

Hello,

I tried to extract data from a website but it didn't work. Can you please tell me where is the error?

from selenium import webdriver                    # Import module
from selenium.webdriver.common.keys import Keys   # For keyboard keys
from time import sleep

URL = 'https://www.comobila.com/covoiturage/trajet/rechercher'
#port=0, executable_path="/usr/bin/safaridriver", quiet=False
driver = webdriver.Safari(executable_path="/usr/bin/safaridriver")
driver.maximize_window()
driver.get(URL)
drivers = []
from_to = []
dates_times = []
prices = []
sleep(20)
drivers_info = driver.find_elements_by_xpath('//div[@class = "recent-ride-row-img"]')
trip_info =  driver.find_elements_by_xpath('//div[@class = "recent-ride-row-info"]')
trip_price = driver.find_elements_by_xpath('//div[@class = "recent-ride-row-price"]')
for i in range(len(drivers_info)):
    drivers.append(drivers_info[i].text.split('\n'))
    from_to.append(trip_info[i].text.split('\n')[0].split(' '))
    if trip_info[i].text.split('\n')[1].startswith('Date'):
        dates_times.append(tripinfos[i].text.split('\n')[1].split(': ')[1].split(' - '))
    else:
        dates_times.append(tripinfos[i].text.split('\n')[2].split(': ')[1].split(' - '))
prices.append(tripprice[i].text.split('\n')[0])
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
sleep(20)
driver.find_element_by_xpath("/html/body/div[2]/div[1]/div[2]/div[2]/div[2]/div/div[2]/div/div[4]/ul/li[13]/a").click()
out = open('COVTrips.csv','w')
out.write('driver_name;driver_sex;driver_age;driver_is_smoking;from;to;date;time;price\n')
for i in range(len(drivers)):
    out.write(drivers[i][0]+';'+drivers[i][1].split(' | ')[0]+';'+drivers[i][1].split(' | ')[1]+';'+drivers[i][2].split(' : ')[1]+';'+from_to[i][0]+';'+from_to[i][1]+';'+dates_times[i][0]+';'+dates_times[i][1]+';'+prices[i]+'\n');

driver.close()
Apr 24 in Selenium by anonymous
• 120 points
58 views
Any specific error that you are getting in the logs?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

0 votes
1 answer

How can I automate Menu links of a website and validate page titles? Please help.

You could probably try following these steps ...READ MORE

answered Nov 29, 2019 in Selenium by Sirajul
• 53,110 points
75 views
0 votes
1 answer

i have a error in automation

Instead of using Xpath, can you use ...READ MORE

answered Oct 15, 2019 in Selenium by Abha
• 27,920 points
222 views
+3 votes
1 answer

How to read excel file numeric data of all rows and column in selenium? I have 10 rows and 5 column but I read Only String value not a Numeric value?

Hey, @Mahendra, check this thread https://www.edureka.co/community/52170/read-numeric-data-from-excel-sheet-using-selenium-webdriver It deals with ...READ MORE

answered Jan 27 in Selenium by Sirajul
• 53,110 points
244 views
0 votes
1 answer

Not able to use “explicit wait” in my code

To wait until the entire data has ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,510 points
170 views
0 votes
1 answer

How do i change the location where my file gets downloaded in Selenium Webdriver and firefox driver?

There are a couple of errors there. ...READ MORE

answered Apr 12, 2018 in Selenium by nsv999
• 5,510 points
2,715 views
0 votes
2 answers

When executing my Jenkins tests with Selenium WebDriver, I do not see a GUI.

Hi eLiJha, I also faced the same issue ...READ MORE

answered Jul 15, 2019 in Selenium by nayan
• 160 points
3,641 views
0 votes
2 answers
0 votes
1 answer