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, 2020 in Selenium by anonymous
• 120 points
726 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

+1 vote
0 answers

Hello i have written below code to verify title using POM method but i am not able to print please help me

public static void verifytitle() { String Createanewaccounttttt=driver.getTitle(); System.out.println("Title is"+Createanewaccounttttt); String excepted_title="Create ...READ MORE

Sep 24, 2020 in Selenium by Jordan
• 410 points
760 views
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
• 59,230 points
3,532 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
• 28,140 points
1,586 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, 2020 in Selenium by Sirajul
• 59,230 points
2,063 views
0 votes
0 answers

I cannot click on the last element and i have been trying for hours PLEASE HELP!!!

from selenium import webdriver from selenium.webdriver.chrome.options import Options from ...READ MORE

Jun 18, 2020 in Selenium by Justin
• 140 points

recategorized Jun 18, 2020 by Gitika 823 views
0 votes
1 answer

I am not able to generate extent report with screenshot in selenium cucumber java .. Please help me out

Hello @kanikahans, You need to define Extent Report ...READ MORE

answered Aug 24, 2020 in Selenium by Niroj
• 82,880 points
8,445 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP