Web scrape Appointment Workbook to a text file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












This is a Web scraping script I wrote to get data from my companies Appointment workbook into a text file so I can review each appointment that is made online through our website. The context is that I use the data in the text file to look up each appointment to get the car VIN and reschedule the appointment under my name. It saves me a lot of time using a script to get the data I need to get the Vin number of each car in every appointment.



Does this follow the common practices of Python scripts? Are nested loops common practice when making a script? The script also can be used for the Acura workbook with a change of one line, which I did to make a second Acura Script.



from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time


def login():
#open text file to write
f = open('Honda_Appt_lists.text', 'w')
#find chrome Driver
browser = webdriver.Chrome('C:\Users\Eddie\Desktop\Script\chromedriver.exe')
#open browser to site
browser.get('https://login.xtime.com/')
#sleep to load full site
#Maximize window
browser.maximize_window()
time.sleep(5)
#Switch to the Iframe I need
browser.switch_to.frame('login')
#input login info and submit
browser.find_element_by_id('login').send_keys('username')
browser.find_element_by_id('password').send_keys('password')
browser.find_element_by_class_name('basic-button').click()
#sleep
time.sleep(5)
#Launch Honda
index = 0
while True:
honda = browser.find_elements_by_class_name('launch-button')
try:
index = index + 1
honda[index].click()
except IndexError:
break

time.sleep(10)
#Goes to workbook
#Applies Filters
browser.find_element_by_xpath('//*[@id="xt_common_header_button-1042"]').click()
time.sleep(10)
element = browser.find_element_by_id('button-1239-btnIconEl')
browser.execute_script("arguments[0].click();", element)
web_element = browser.find_element_by_xpath('//*[@id="treeview-1206-record-ext-record-163"]/td/div/span')
browser.execute_script("arguments[0].click();", web_element)
browser.find_element_by_xpath('//*[@id="button-1233-btnIconEl"]').click()
time.sleep(10)
#Sort by status
browser.find_element_by_xpath('//*[@id="button-1257-btnIconEl"]').click()
browser.implicitly_wait(5)
def calender_changer(x):
while x < 31 and x > 15:
#Find calender
div = browser.find_element_by_id('ledgerdateslider-1247-innerCt')
#hit calender
div.find_element_by_xpath('//*[@id="component-1250"]/div/table/tbody/tr/td[1]').click()
#hit calender date
browser.implicitly_wait(5)
browser.find_element_by_link_text(str(x)).click()
time.sleep(10)
try:
index = 0
while True:
header = browser.find_elements_by_class_name('x-ledgerdataview-header')
try:
time.sleep(5)
header[index].click()
while True:
name = browser.find_elements_by_class_name('x-lightcard-customer-name')
car = browser.find_elements_by_class_name('x-lightcard-vehicle-inf')
apt_time = browser.find_elements_by_class_name('x-lightcard-header-right')
contact = browser.find_elements_by_class_name('x-lightcard-contact')
note = browser.find_elements_by_class_name('x-lightcard-services')
try:
# print and write to file name/car/apt_time/contact/note
print(name[index].text)
f.write("n" + 'Name: ' + name[index].text + "n")
print(car[index].text)
f.write('Car: ' + car[index].text + "n")
print(apt_time[index].text)
f.write('Time: ' + apt_time[index].text + "n")
print(contact[index].text)
f.write('Contact: ' + contact[index].text + "n")
print(note[index].text)
f.write('Service Notes:' + note[index].text + "n")
print(x)
f.write('Date:' + x + "n")
break
except IndexError:
break

except IndexError:
x = x - 1
break
except NoSuchElementException:
x = x -1
print(x)
calender_changer(30)
time.sleep(5)
f.close()
login()






share|improve this question



























    up vote
    0
    down vote

    favorite












    This is a Web scraping script I wrote to get data from my companies Appointment workbook into a text file so I can review each appointment that is made online through our website. The context is that I use the data in the text file to look up each appointment to get the car VIN and reschedule the appointment under my name. It saves me a lot of time using a script to get the data I need to get the Vin number of each car in every appointment.



    Does this follow the common practices of Python scripts? Are nested loops common practice when making a script? The script also can be used for the Acura workbook with a change of one line, which I did to make a second Acura Script.



    from selenium import webdriver
    from selenium.common.exceptions import NoSuchElementException
    import time


    def login():
    #open text file to write
    f = open('Honda_Appt_lists.text', 'w')
    #find chrome Driver
    browser = webdriver.Chrome('C:\Users\Eddie\Desktop\Script\chromedriver.exe')
    #open browser to site
    browser.get('https://login.xtime.com/')
    #sleep to load full site
    #Maximize window
    browser.maximize_window()
    time.sleep(5)
    #Switch to the Iframe I need
    browser.switch_to.frame('login')
    #input login info and submit
    browser.find_element_by_id('login').send_keys('username')
    browser.find_element_by_id('password').send_keys('password')
    browser.find_element_by_class_name('basic-button').click()
    #sleep
    time.sleep(5)
    #Launch Honda
    index = 0
    while True:
    honda = browser.find_elements_by_class_name('launch-button')
    try:
    index = index + 1
    honda[index].click()
    except IndexError:
    break

    time.sleep(10)
    #Goes to workbook
    #Applies Filters
    browser.find_element_by_xpath('//*[@id="xt_common_header_button-1042"]').click()
    time.sleep(10)
    element = browser.find_element_by_id('button-1239-btnIconEl')
    browser.execute_script("arguments[0].click();", element)
    web_element = browser.find_element_by_xpath('//*[@id="treeview-1206-record-ext-record-163"]/td/div/span')
    browser.execute_script("arguments[0].click();", web_element)
    browser.find_element_by_xpath('//*[@id="button-1233-btnIconEl"]').click()
    time.sleep(10)
    #Sort by status
    browser.find_element_by_xpath('//*[@id="button-1257-btnIconEl"]').click()
    browser.implicitly_wait(5)
    def calender_changer(x):
    while x < 31 and x > 15:
    #Find calender
    div = browser.find_element_by_id('ledgerdateslider-1247-innerCt')
    #hit calender
    div.find_element_by_xpath('//*[@id="component-1250"]/div/table/tbody/tr/td[1]').click()
    #hit calender date
    browser.implicitly_wait(5)
    browser.find_element_by_link_text(str(x)).click()
    time.sleep(10)
    try:
    index = 0
    while True:
    header = browser.find_elements_by_class_name('x-ledgerdataview-header')
    try:
    time.sleep(5)
    header[index].click()
    while True:
    name = browser.find_elements_by_class_name('x-lightcard-customer-name')
    car = browser.find_elements_by_class_name('x-lightcard-vehicle-inf')
    apt_time = browser.find_elements_by_class_name('x-lightcard-header-right')
    contact = browser.find_elements_by_class_name('x-lightcard-contact')
    note = browser.find_elements_by_class_name('x-lightcard-services')
    try:
    # print and write to file name/car/apt_time/contact/note
    print(name[index].text)
    f.write("n" + 'Name: ' + name[index].text + "n")
    print(car[index].text)
    f.write('Car: ' + car[index].text + "n")
    print(apt_time[index].text)
    f.write('Time: ' + apt_time[index].text + "n")
    print(contact[index].text)
    f.write('Contact: ' + contact[index].text + "n")
    print(note[index].text)
    f.write('Service Notes:' + note[index].text + "n")
    print(x)
    f.write('Date:' + x + "n")
    break
    except IndexError:
    break

    except IndexError:
    x = x - 1
    break
    except NoSuchElementException:
    x = x -1
    print(x)
    calender_changer(30)
    time.sleep(5)
    f.close()
    login()






    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      This is a Web scraping script I wrote to get data from my companies Appointment workbook into a text file so I can review each appointment that is made online through our website. The context is that I use the data in the text file to look up each appointment to get the car VIN and reschedule the appointment under my name. It saves me a lot of time using a script to get the data I need to get the Vin number of each car in every appointment.



      Does this follow the common practices of Python scripts? Are nested loops common practice when making a script? The script also can be used for the Acura workbook with a change of one line, which I did to make a second Acura Script.



      from selenium import webdriver
      from selenium.common.exceptions import NoSuchElementException
      import time


      def login():
      #open text file to write
      f = open('Honda_Appt_lists.text', 'w')
      #find chrome Driver
      browser = webdriver.Chrome('C:\Users\Eddie\Desktop\Script\chromedriver.exe')
      #open browser to site
      browser.get('https://login.xtime.com/')
      #sleep to load full site
      #Maximize window
      browser.maximize_window()
      time.sleep(5)
      #Switch to the Iframe I need
      browser.switch_to.frame('login')
      #input login info and submit
      browser.find_element_by_id('login').send_keys('username')
      browser.find_element_by_id('password').send_keys('password')
      browser.find_element_by_class_name('basic-button').click()
      #sleep
      time.sleep(5)
      #Launch Honda
      index = 0
      while True:
      honda = browser.find_elements_by_class_name('launch-button')
      try:
      index = index + 1
      honda[index].click()
      except IndexError:
      break

      time.sleep(10)
      #Goes to workbook
      #Applies Filters
      browser.find_element_by_xpath('//*[@id="xt_common_header_button-1042"]').click()
      time.sleep(10)
      element = browser.find_element_by_id('button-1239-btnIconEl')
      browser.execute_script("arguments[0].click();", element)
      web_element = browser.find_element_by_xpath('//*[@id="treeview-1206-record-ext-record-163"]/td/div/span')
      browser.execute_script("arguments[0].click();", web_element)
      browser.find_element_by_xpath('//*[@id="button-1233-btnIconEl"]').click()
      time.sleep(10)
      #Sort by status
      browser.find_element_by_xpath('//*[@id="button-1257-btnIconEl"]').click()
      browser.implicitly_wait(5)
      def calender_changer(x):
      while x < 31 and x > 15:
      #Find calender
      div = browser.find_element_by_id('ledgerdateslider-1247-innerCt')
      #hit calender
      div.find_element_by_xpath('//*[@id="component-1250"]/div/table/tbody/tr/td[1]').click()
      #hit calender date
      browser.implicitly_wait(5)
      browser.find_element_by_link_text(str(x)).click()
      time.sleep(10)
      try:
      index = 0
      while True:
      header = browser.find_elements_by_class_name('x-ledgerdataview-header')
      try:
      time.sleep(5)
      header[index].click()
      while True:
      name = browser.find_elements_by_class_name('x-lightcard-customer-name')
      car = browser.find_elements_by_class_name('x-lightcard-vehicle-inf')
      apt_time = browser.find_elements_by_class_name('x-lightcard-header-right')
      contact = browser.find_elements_by_class_name('x-lightcard-contact')
      note = browser.find_elements_by_class_name('x-lightcard-services')
      try:
      # print and write to file name/car/apt_time/contact/note
      print(name[index].text)
      f.write("n" + 'Name: ' + name[index].text + "n")
      print(car[index].text)
      f.write('Car: ' + car[index].text + "n")
      print(apt_time[index].text)
      f.write('Time: ' + apt_time[index].text + "n")
      print(contact[index].text)
      f.write('Contact: ' + contact[index].text + "n")
      print(note[index].text)
      f.write('Service Notes:' + note[index].text + "n")
      print(x)
      f.write('Date:' + x + "n")
      break
      except IndexError:
      break

      except IndexError:
      x = x - 1
      break
      except NoSuchElementException:
      x = x -1
      print(x)
      calender_changer(30)
      time.sleep(5)
      f.close()
      login()






      share|improve this question













      This is a Web scraping script I wrote to get data from my companies Appointment workbook into a text file so I can review each appointment that is made online through our website. The context is that I use the data in the text file to look up each appointment to get the car VIN and reschedule the appointment under my name. It saves me a lot of time using a script to get the data I need to get the Vin number of each car in every appointment.



      Does this follow the common practices of Python scripts? Are nested loops common practice when making a script? The script also can be used for the Acura workbook with a change of one line, which I did to make a second Acura Script.



      from selenium import webdriver
      from selenium.common.exceptions import NoSuchElementException
      import time


      def login():
      #open text file to write
      f = open('Honda_Appt_lists.text', 'w')
      #find chrome Driver
      browser = webdriver.Chrome('C:\Users\Eddie\Desktop\Script\chromedriver.exe')
      #open browser to site
      browser.get('https://login.xtime.com/')
      #sleep to load full site
      #Maximize window
      browser.maximize_window()
      time.sleep(5)
      #Switch to the Iframe I need
      browser.switch_to.frame('login')
      #input login info and submit
      browser.find_element_by_id('login').send_keys('username')
      browser.find_element_by_id('password').send_keys('password')
      browser.find_element_by_class_name('basic-button').click()
      #sleep
      time.sleep(5)
      #Launch Honda
      index = 0
      while True:
      honda = browser.find_elements_by_class_name('launch-button')
      try:
      index = index + 1
      honda[index].click()
      except IndexError:
      break

      time.sleep(10)
      #Goes to workbook
      #Applies Filters
      browser.find_element_by_xpath('//*[@id="xt_common_header_button-1042"]').click()
      time.sleep(10)
      element = browser.find_element_by_id('button-1239-btnIconEl')
      browser.execute_script("arguments[0].click();", element)
      web_element = browser.find_element_by_xpath('//*[@id="treeview-1206-record-ext-record-163"]/td/div/span')
      browser.execute_script("arguments[0].click();", web_element)
      browser.find_element_by_xpath('//*[@id="button-1233-btnIconEl"]').click()
      time.sleep(10)
      #Sort by status
      browser.find_element_by_xpath('//*[@id="button-1257-btnIconEl"]').click()
      browser.implicitly_wait(5)
      def calender_changer(x):
      while x < 31 and x > 15:
      #Find calender
      div = browser.find_element_by_id('ledgerdateslider-1247-innerCt')
      #hit calender
      div.find_element_by_xpath('//*[@id="component-1250"]/div/table/tbody/tr/td[1]').click()
      #hit calender date
      browser.implicitly_wait(5)
      browser.find_element_by_link_text(str(x)).click()
      time.sleep(10)
      try:
      index = 0
      while True:
      header = browser.find_elements_by_class_name('x-ledgerdataview-header')
      try:
      time.sleep(5)
      header[index].click()
      while True:
      name = browser.find_elements_by_class_name('x-lightcard-customer-name')
      car = browser.find_elements_by_class_name('x-lightcard-vehicle-inf')
      apt_time = browser.find_elements_by_class_name('x-lightcard-header-right')
      contact = browser.find_elements_by_class_name('x-lightcard-contact')
      note = browser.find_elements_by_class_name('x-lightcard-services')
      try:
      # print and write to file name/car/apt_time/contact/note
      print(name[index].text)
      f.write("n" + 'Name: ' + name[index].text + "n")
      print(car[index].text)
      f.write('Car: ' + car[index].text + "n")
      print(apt_time[index].text)
      f.write('Time: ' + apt_time[index].text + "n")
      print(contact[index].text)
      f.write('Contact: ' + contact[index].text + "n")
      print(note[index].text)
      f.write('Service Notes:' + note[index].text + "n")
      print(x)
      f.write('Date:' + x + "n")
      break
      except IndexError:
      break

      except IndexError:
      x = x - 1
      break
      except NoSuchElementException:
      x = x -1
      print(x)
      calender_changer(30)
      time.sleep(5)
      f.close()
      login()








      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 9 at 22:34









      Jamal♦

      30.1k11114225




      30.1k11114225









      asked Jun 9 at 15:23









      BlackHazrd

      14




      14

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f196164%2fweb-scrape-appointment-workbook-to-a-text-file%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f196164%2fweb-scrape-appointment-workbook-to-a-text-file%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?