Nov-04-2018, 11:14 AM
hello ladies and gentleman i built an automation bot with selenium and webdriver and everything was working fine
but after i tried to add a function to make the bot works with proxy list .txt i found a lot of issues could you please showme where is the problem and if u r able to fix and and thnx in advance
but after i tried to add a function to make the bot works with proxy list .txt i found a lot of issues could you please showme where is the problem and if u r able to fix and and thnx in advance
from selenium import webdriver from time import sleep import os from selenium.webdriver.support.ui import Select, WebDriverWait from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as EC from pynput.keyboard import Key, Controller import traceback keyboard = Controller() def make_appointment(member): #adding the webdriver options so we don't encounter some problems options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_argument('disable-infobars') ################################ # HELPER FUNCTIONS DEFINITIONS # ################################ ############################ # MAIN FUNCTION DEFINITION # ############################ def get_input(): IP = [] with open ("ips.txt", 'r') as file_input: for line in file_input: x = (line.strip()) IP.append(x) return IP def configure_driver(ip): options = webdriver.ChromeOptions() next_server = "--proxy-server=" + ip options.add_argument(next_server) #options.add_argument("headless") driver = webdriver.Chrome(chrome_options=options) return driver #reading a text file containing all the info we want to pass to the application, then passing that info filepath = 'C:/Users/rzlt/Desktop/member' + str(member) + '.txt' with open(filepath) as fp: lines = fp.readlines() driver = webdriver.Chrome(chrome_options=options) return driver for ip in i: driver = configure_driver(ip) driver.get('http://egypt.blsspainvisa.com/book_appointment.php') #open webpage try: driver.find_element_by_xpath('//*[@id="IDBodyPanelapp"]/div[1]').click() #clicks the 'X'(close) button if it appears except: print("Exception occured, pop up didn't appear") time.sleep(3) #selecting the 'Cairo' centre option select = Select(driver.find_element_by_id('centre')) time.sleep(2) select.select_by_visible_text('Cairo') #filling phone text field driver.find_element_by_id('phone').send_keys(lines[1]) #getting a spare email address using 'https://temp-mail.org/' webpage and passing it to the text field #after that, retrieving the verification code sent to that address current_window = driver.current_window_handle driver.execute_script("window.open('https://temp-mail.org')") WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2)) windows_after = driver.window_handles new_window = [x for x in windows_after if x != current_window][0] driver.switch_to_window(new_window) spare_email = driver.find_element_by_id('mail').get_attribute('value') driver.switch_to_window(current_window) driver.find_element_by_id('email').send_keys(spare_email) driver.find_element_by_xpath('//*[@id="em_tr"]/div[2]/abbr/a').click() driver.switch_to_window(new_window) time.sleep(10) driver.find_element_by_xpath('//*[@id="mails"]/tbody/tr/td[3]/a/span').click() time.sleep(2) ver_code = driver.find_element_by_xpath('/html/body/div[2]/div/div/div[2]/div[1]/div[1]/div[3]/div/div/table').text[-4:] driver.switch_to_window(current_window) driver.find_element_by_id('otp').send_keys(ver_code) #pressing the 'continue' button and then the 'agree' button driver.find_element_by_name('save').click() driver.find_element_by_name('agree').click() appointment_made = False while(not appointment_made): try: driver.find_element_by_xpath('//*[@id="app_date"]').click() #this makes the datepicker appear all_appointments = driver.find_elements_by_xpath('//*[@title="Book"]') #print(all_appointments) if len(all_appointments) != 0: all_appointments[0].click() appointment_made = True except: print("Exception occured...") keyboard.press(Key.f5) time.sleep(4) traceback.print_exc() driver.find_element_by_xpath('//*[@id="app_time"]/option[2]').click() #sets the Appointment Time driver.find_element_by_xpath('//*[@id="VisaTypeId"]/option[2]').click() #sets the Visa Type driver.find_element_by_id('first_name').send_keys(lines[2]) #sets the first name driver.find_element_by_id('last_name').send_keys(lines[3]) #sets the last name driver.execute_script("document.getElementById('dateOfBirth').value=" + lines[4]) #sets the Date Of Birth driver.find_element_by_id('passport_no').send_keys(lines[5]) #sets the Passport Number driver.execute_script("document.getElementById('pptIssueDate').value=" + lines[6]) #sets the Passport Issue Date driver.execute_script("document.getElementById('pptExpiryDate').value=" + lines[7]) #sets the Passport Expiry Date driver.find_element_by_id('pptIssuePalace').send_keys(lines[8]) #sets the passport Issue Place except: pass print ("we are beeing redirectedddd -----> ip is blocked") print ("starting with next available IP") time.sleep(100)