Я пытаюсь создать систему для автоматизации процедуры входа на booking.com.
Что я хочу сделать sh, это когда я посещаю следующую страницу: https://join.booking.com/?lang=it, браузер должен показать мне форму входа, когда я впервые ее посещал.
К сожалению, этого не происходит, почему-то Firefox помнит, что у меня есть что-то уже сделано на этой странице и покажи мне страницу "продолжить регистрацию". Я читал, что селен всегда имеет свободный запуск sh, я отключил кеш-память, автозаполнение формы, но все равно не могу это сделать.
Есть предложения? Может быть, нужно установить какое-то предпочтение Firefox, например, кеш-память e cc ...
Работа с python 2.7.9, селеном 3.141.0 и geckodriver 0.26.0
import time
import sys
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
def initialize_driver():
options = Options()
options.headless = True
options.add_argument("--private")
print(options)
driver = webdriver.Firefox(executable_path='/Users/giovanni/Documents/IA_beta_v0.0.0/tools/geckodriver', options=options)
try:
driver.get("https://www.google.com")
print("Driver successfully initialized\n")
except:
print("Error while initializing driver\n")
return driver
def close_driver(driver):
try:
driver.close()
print("Driver closed correclty\n")
except:
print("An error occured when trying to shut down driver\n")
def new_registration():
print("Enter name: ")
name = raw_input()
print("Enter surname: ")
surname = raw_input()
print("Enter email: ")
email_address = raw_input()
print("\nPlease check the information you have entered:\n")
print("Name = %s;\n" %name)
print("Surname = %s;\n" %surname)
print("Email address = %s;\n" %email_address)
print("Are these information correct?(y/n)\n")
user_answer = raw_input()
if user_answer == 'y':
print("Proceeding with entablishing connection with Booking.com\n")
elif user_answer == 'n':
print("What information would you like to change?\n")
print("\t-name;\n")
print("\t-surname;\n")
print("\t-email;\n")
user_answer = raw_input()
if user_answer == 'name':
print("You have choose to modify the name for the registration\n")
name = substitute_info_registration(1,name)
print("\nNew name is %s\n" %name)
elif user_answer == 'surname':
print("You have choose to modify the surname for the registration\n")
surname = substitute_info_registration(2,surname)
print("\nNew name is %s\n" %surname)
elif user_answer == 'email':
print("You have choose to modify the email address for the registration\n")
email_address = substitute_info_registration(3,email_address)
print("\nNew name is %s\n" %email_address)
else:
print("Wrong input. Please enter one of the three options\n")
else:
print("Wrong input. Please enter one of the two options\n")
booking_registration_procedure(name,surname,email_address)
def substitute_info_registration(flag,info):
if flag == 1:
print("Current name is %s. Which is going to be the new name? " %info)
user_answer = raw_input()
print("New name is %s.\n" %user_answer)
elif flag == 2:
print("Current surname is %s. Which is going to be the new surname? " %info)
user_answer = raw_input()
print("New surname is %s.\n" %user_answer)
elif flag == 3:
print("Current email address is %s. Which is going to be the new email address? " %info)
user_answer = raw_input()
print("New email address is %s.\n" %user_answer)
return user_answer
def booking_registration_procedure(name,surname,email_address):
print("Initializing driver...\n")
firefox = initialize_driver()
#STEP 1
firefox.get('https://join.booking.com/?lang=it')
#source = firefox.page_source
try:
firefox.save_screenshot('/Users/giovanni/Documents/IA_beta_v0.0.0/screenshot/first_page.jpg')
print("Screenshot taken correctly\n")
except:
print("Can't take first screenshot\n")
try:
name_surname_form = firefox.find_element_by_id('ultranet_label_input_0')
name_surname_form.send_keys(name + " " + surname)
email_address_form = firefox.find_element_by_id('ultranet_label_input_1')
email_address_form.send_keys(email_address)
firefox.save_screenshot('/Users/giovanni/Documents/IA_beta_v0.0.0/screenshot/first_page_after_filling_form.jpg')
except:
print("Can't fill form with name, surname and email address\n")
close_driver(firefox)
exit(1)
try:
continue_button = firefox.find_elements_by_name('save')
print continue_button
continue_button[0].click()
time.sleep(2)
firefox.save_screenshot('/Users/giovanni/Documents/IA_beta_v0.0.0/screenshot/first_page_after_clicking_button.jpg')
except:
print("Can't click continue button\n")
close_driver(firefox)