Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.79 KB | None | 0 0
  1. from time import sleep
  2.  
  3. import requests
  4. from selenium.webdriver import Firefox
  5.  
  6.  
  7. def check_form_on_page():
  8.     print("Checking for on page")
  9.     url = "http://www.europaplus.ru/index.php?go=News&in=view&id=29903"
  10.     # return requests.get(url).text.find('docs.google.com/forms') != -1
  11.     return True
  12.  
  13.  
  14. def main():
  15.     driver_1 = FormSubmitter(fake=True)
  16.     driver_2 = FormSubmitter(fake=True)
  17.     driver_3 = FormSubmitter(fake=True)
  18.     driver_1.fill_form(PERSONS[0])
  19.     driver_2.fill_form(PERSONS[1])
  20.     driver_3.fill_form(PERSONS[2])
  21.  
  22.     try:
  23.         while True:
  24.             if check_form_on_page():
  25.                 print("Form on page")
  26.                 sleep(500)
  27.                 # driver_1.submit_form()
  28.                 # driver_2.submit_form()
  29.                 # driver_3.submit_form()
  30.                 break
  31.             else:
  32.                 print("Form is not on page")
  33.                 sleep(3)
  34.  
  35.     finally:
  36.         print("Closing driver")
  37.         driver_1.close()
  38.         driver_2.close()
  39.         driver_3.close()
  40.  
  41.  
  42. class Person(object):
  43.     def __init__(self, surname, first_name, email, number, city):
  44.         self.surname = surname
  45.         self.first_name = first_name
  46.         self.email = email
  47.         self.number = number
  48.         self.city = city
  49.  
  50.  
  51. PERSONS = [
  52.     Person(u"Дементьев", u"Алексей", "alexdamon@mail.ru", "89096669399", u"Москва"),
  53.     Person(u"Шевцов", u"Антон", "Shevan05@gmail.com", "89197237244", u"Москва"),
  54.     Person(u"Артёмова", u"Анастасия", "anastasia.arto@gmail.com", "89104668224", u"Москва"),
  55. ]
  56.  
  57. ANSWERS = [
  58.     "W&W",
  59.     "Alexander Popov",
  60.     "Apashe",
  61.     "Zeskullz",
  62.     "Cosmic Gate"
  63. ]
  64.  
  65.  
  66. class FormSubmitter(Firefox):
  67.     def __init__(self, fake=False):
  68.         super(FormSubmitter, self).__init__()
  69.  
  70.         self.xpath_first_name = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[7]/div[2]/div/div[1]/div/div[1]/input'
  71.         self.xpath_surname = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[6]/div[2]/div/div[1]/div/div[1]/input'
  72.         self.xpath_email = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[8]/div[2]/div/div[1]/div/div[1]/input'
  73.         self.xpath_number = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[9]/div[2]/div/div[1]/div/div[1]/input'
  74.         self.xpath_city = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[10]/div[2]/div/div[1]/div/div[1]/input'
  75.  
  76.         self.xpath_answer1 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[1]/div[2]/div/div[1]/div/div[1]/input'
  77.         self.xpath_answer2 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[2]/div[2]/div/div[1]/div/div[1]/input'
  78.         self.xpath_answer3 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[3]/div[2]/div/div[1]/div/div[1]/input'
  79.         self.xpath_answer4 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/input'
  80.         self.xpath_answer5 = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[5]/div[2]/div/div[1]/div/div[1]/input'
  81.  
  82.         self.xpath_checkbox = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div[11]/div[2]/div/content/div/label/div/div[1]/div[3]/div'
  83.         self.xpath_submit = '//*[@id="mG61Hd"]/div/div[2]/div[3]/div[1]/div/div/content/span'
  84.  
  85.         if fake:
  86.             self.form_url = \
  87.                 "https://docs.google.com/forms/d/e/1FAIpQLScHoO2RQg9IH6q-6UX50jCtUDNlVmT3jRDqgRFKy8I-ciaUPQ/viewform"
  88.         else:
  89.             self.form_url = \
  90.                 "https://docs.google.com/forms/d/e/1FAIpQLSff-Id0MrWOx9wCWrUanYd1go4z4Xpw8or4RMuoiPumKz7faA/viewform"
  91.  
  92.         self.get(self.form_url)
  93.  
  94.     def fill_form(self, person):
  95.  
  96.         # self.find_element_by_xpath(self.xpath_first_name).send_keys(Keys.CONTROL + Keys.TAB)
  97.  
  98.         print("Filling for %s %s" % (person.first_name, person.surname))
  99.  
  100.         self.find_element_by_xpath(self.xpath_answer1).send_keys(ANSWERS[0])
  101.         self.find_element_by_xpath(self.xpath_answer2).send_keys(ANSWERS[1])
  102.         self.find_element_by_xpath(self.xpath_answer3).send_keys(ANSWERS[2])
  103.         self.find_element_by_xpath(self.xpath_answer5).send_keys(ANSWERS[3])
  104.         self.find_element_by_xpath(self.xpath_answer4).send_keys(ANSWERS[4])
  105.  
  106.         self.find_element_by_xpath(self.xpath_surname).send_keys(person.surname)
  107.         self.find_element_by_xpath(self.xpath_first_name).send_keys(person.first_name)
  108.         self.find_element_by_xpath(self.xpath_email).send_keys(person.email)
  109.         self.find_element_by_xpath(self.xpath_number).send_keys(person.number)
  110.         self.find_element_by_xpath(self.xpath_city).send_keys(person.city)
  111.  
  112.         self.find_element_by_xpath(self.xpath_checkbox).click()
  113.  
  114.         print("Filled for for %s %s" % (person.first_name, person.surname))
  115.  
  116.     def submit_form(self):
  117.         self.find_element_by_xpath(self.xpath_submit).click()
  118.  
  119.  
  120. if __name__ == "__main__":
  121.     print("Launching main...")
  122.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement