Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import sleep
- import requests
- from selenium.webdriver import Firefox
- def check_form_on_page():
- print("Checking for on page")
- url = "http://www.europaplus.ru/index.php?go=News&in=view&id=29903"
- # return requests.get(url).text.find('docs.google.com/forms') != -1
- return True
- def main():
- driver_1 = FormSubmitter(fake=True)
- driver_2 = FormSubmitter(fake=True)
- driver_3 = FormSubmitter(fake=True)
- driver_1.fill_form(PERSONS[0])
- driver_2.fill_form(PERSONS[1])
- driver_3.fill_form(PERSONS[2])
- try:
- while True:
- if check_form_on_page():
- print("Form on page")
- sleep(500)
- # driver_1.submit_form()
- # driver_2.submit_form()
- # driver_3.submit_form()
- break
- else:
- print("Form is not on page")
- sleep(3)
- finally:
- print("Closing driver")
- driver_1.close()
- driver_2.close()
- driver_3.close()
- class Person(object):
- def __init__(self, surname, first_name, email, number, city):
- self.surname = surname
- self.first_name = first_name
- self.email = email
- self.number = number
- self.city = city
- PERSONS = [
- Person(u"Дементьев", u"Алексей", "alexdamon@mail.ru", "89096669399", u"Москва"),
- Person(u"Шевцов", u"Антон", "Shevan05@gmail.com", "89197237244", u"Москва"),
- Person(u"Артёмова", u"Анастасия", "anastasia.arto@gmail.com", "89104668224", u"Москва"),
- ]
- ANSWERS = [
- "W&W",
- "Alexander Popov",
- "Apashe",
- "Zeskullz",
- "Cosmic Gate"
- ]
- class FormSubmitter(Firefox):
- def __init__(self, fake=False):
- super(FormSubmitter, self).__init__()
- self.xpath_first_name = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[7]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_surname = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[6]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_email = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[8]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_number = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[9]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_city = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[10]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_answer1 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[1]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_answer2 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[2]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_answer3 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[3]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_answer4 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_answer5 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[5]/div[2]/div/div[1]/div/div[1]/input'
- self.xpath_checkbox = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[11]/div[2]/div/content/div/label/div/div[1]/div[3]/div'
- self.xpath_submit = '//*[@id="mG61Hd"]/div/div[2]/div[3]/div[1]/div/div/content/span'
- if fake:
- self.form_url = \
- "https://docs.google.com/forms/d/e/1FAIpQLScHoO2RQg9IH6q-6UX50jCtUDNlVmT3jRDqgRFKy8I-ciaUPQ/viewform"
- else:
- self.form_url = \
- "https://docs.google.com/forms/d/e/1FAIpQLSff-Id0MrWOx9wCWrUanYd1go4z4Xpw8or4RMuoiPumKz7faA/viewform"
- self.get(self.form_url)
- def fill_form(self, person):
- # self.find_element_by_xpath(self.xpath_first_name).send_keys(Keys.CONTROL + Keys.TAB)
- print("Filling for %s %s" % (person.first_name, person.surname))
- self.find_element_by_xpath(self.xpath_answer1).send_keys(ANSWERS[0])
- self.find_element_by_xpath(self.xpath_answer2).send_keys(ANSWERS[1])
- self.find_element_by_xpath(self.xpath_answer3).send_keys(ANSWERS[2])
- self.find_element_by_xpath(self.xpath_answer5).send_keys(ANSWERS[3])
- self.find_element_by_xpath(self.xpath_answer4).send_keys(ANSWERS[4])
- self.find_element_by_xpath(self.xpath_surname).send_keys(person.surname)
- self.find_element_by_xpath(self.xpath_first_name).send_keys(person.first_name)
- self.find_element_by_xpath(self.xpath_email).send_keys(person.email)
- self.find_element_by_xpath(self.xpath_number).send_keys(person.number)
- self.find_element_by_xpath(self.xpath_city).send_keys(person.city)
- self.find_element_by_xpath(self.xpath_checkbox).click()
- print("Filled for for %s %s" % (person.first_name, person.surname))
- def submit_form(self):
- self.find_element_by_xpath(self.xpath_submit).click()
- if __name__ == "__main__":
- print("Launching main...")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement