You've already forked GoogleFormsFiller
mirror of
https://github.com/Llloooggg/GoogleFormsFiller.git
synced 2026-03-06 02:56:23 +03:00
Рефракторинг, исправлен бросок монетки при выборе профессии
This commit is contained in:
198
__init__.py
198
__init__.py
@@ -8,138 +8,144 @@ from bs4 import BeautifulSoup
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def button_by_text(text): # получение кнопки по тексту на ней
|
def button_by_text(text): # получение кнопки по тексту на ней
|
||||||
|
|
||||||
try:
|
try:
|
||||||
button = driver.find_element_by_xpath(f'//*[contains(text(), "{text}")]')
|
button = driver.find_element_by_xpath(
|
||||||
button.click()
|
f'//*[contains(text(), "{text}")]')
|
||||||
return True
|
button.click()
|
||||||
except Exception:
|
return True
|
||||||
return False
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_profession(): # получение случайной профессии в РФ, где 1 и 2 диапазон - профессии рабочих, 2 и 3 - должности служащих
|
def get_profession(): # получение случайной профессии в РФ, где 1 и 2 диапазон - профессии рабочих, 2 и 3 - должности служащих
|
||||||
while True:
|
|
||||||
|
|
||||||
coin = (1, 2, 3, 4)
|
coin = (1, 2, 3, 4)
|
||||||
coin = random.choices(coin, [0.1, 0.1, 0.4, 0.4], k=1)[0]
|
coin = random.choices(coin, [0.1, 0.1, 0.4, 0.4], k=1)[0]
|
||||||
|
|
||||||
if coin == 1:
|
while True:
|
||||||
code = random.randint(10003, 19975)
|
|
||||||
elif coin == 2:
|
|
||||||
code = random.randint(30018, 33270)
|
|
||||||
elif coin == 3:
|
|
||||||
code = random.randint(20001, 27933)
|
|
||||||
else:
|
|
||||||
code = random.randint(40064, 47110)
|
|
||||||
|
|
||||||
page = requests.get(f'http://okpdtr.ru/?s={code}').text
|
if coin == 1:
|
||||||
soup = BeautifulSoup(page, features='html.parser')
|
code = random.randint(10003, 19975)
|
||||||
try:
|
elif coin == 2:
|
||||||
profession = soup.findAll("div", {"class": "my_col2"})[1]
|
code = random.randint(30018, 33270)
|
||||||
profession = re.sub(r'\([^()]*\)', '', profession.get_text())
|
elif coin == 3:
|
||||||
return profession
|
code = random.randint(20001, 27933)
|
||||||
except:
|
else:
|
||||||
pass
|
code = random.randint(40064, 47110)
|
||||||
|
|
||||||
|
page = requests.get(f'http://okpdtr.ru/?s={code}').text
|
||||||
|
soup = BeautifulSoup(page, features='html.parser')
|
||||||
|
try:
|
||||||
|
profession = soup.findAll("div", {"class": "my_col2"})[1]
|
||||||
|
profession = re.sub(r'\([^()]*\)', '', profession.get_text())
|
||||||
|
return profession
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def profile_maker():
|
def profile_maker():
|
||||||
|
|
||||||
global areas_of_activity
|
global areas_of_activity
|
||||||
|
|
||||||
forms_list = driver.find_elements_by_class_name('freebirdFormviewerViewItemsItemItem') # получение форм со страницы
|
forms_list = driver.find_elements_by_class_name(
|
||||||
for form in forms_list:
|
'freebirdFormviewerViewItemsItemItem') # получение форм со страницы
|
||||||
|
for form in forms_list:
|
||||||
|
|
||||||
header = form.find_element_by_class_name('freebirdFormviewerViewItemsItemItemHeader').text # получение заголовка формы
|
header = form.find_element_by_class_name(
|
||||||
|
'freebirdFormviewerViewItemsItemItemHeader').text # получение заголовка формы
|
||||||
|
|
||||||
if header[-1:] == '*':
|
if header[-1:] == '*':
|
||||||
header = header[:-2]
|
header = header[:-2]
|
||||||
|
|
||||||
if header == 'Укажите Ваш пол':
|
if header == 'Укажите Ваш пол':
|
||||||
buttons_list = form.find_elements_by_class_name('appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
buttons_list = form.find_elements_by_class_name(
|
||||||
button = random.choices(buttons_list, [0.7, 0.3], k=1)[0]
|
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||||
button.click()
|
button = random.choices(buttons_list, [0.7, 0.3], k=1)[0]
|
||||||
|
button.click()
|
||||||
|
|
||||||
elif header == 'Укажите Ваш возраст (полных лет)':
|
elif header == 'Укажите Ваш возраст (полных лет)':
|
||||||
age = random.randint(18, 56)
|
age = random.randint(18, 56)
|
||||||
field = form.find_elements_by_class_name('quantumWizTextinputPaperinputInput')[0] # получение полей для ввода с формы
|
field = form.find_elements_by_class_name('quantumWizTextinputPaperinputInput')[
|
||||||
field.click()
|
0] # получение полей для ввода с формы
|
||||||
field.send_keys(age)
|
field.click()
|
||||||
|
field.send_keys(age)
|
||||||
|
|
||||||
elif header == 'Укажите Ваше образование (возможно несколько вариантов)':
|
elif header == 'Укажите Ваше образование (возможно несколько вариантов)':
|
||||||
buttons_list = form.find_elements_by_class_name('quantumWizTogglePapercheckboxEl') # получение чекбоксов с формы
|
buttons_list = form.find_elements_by_class_name(
|
||||||
buttons_list[random.randint(0, 4)].click()
|
'quantumWizTogglePapercheckboxEl') # получение чекбоксов с формы
|
||||||
|
buttons_list[random.randint(0, 4)].click()
|
||||||
|
|
||||||
elif header == 'Выберите из списка основную сферу деятельности организации, в которой Вы сейчас работаете':
|
elif header == 'Выберите из списка основную сферу деятельности организации, в которой Вы сейчас работаете':
|
||||||
form.find_elements_by_class_name('quantumWizMenuPaperselectOption')[0].click()
|
form.find_elements_by_class_name(
|
||||||
coin = random.randint(3, 24)
|
'quantumWizMenuPaperselectOption')[0].click()
|
||||||
variants_list = form.find_element_by_xpath(f'//*[@id="mG61Hd"]/div/div/div[2]/div[5]/div/div[2]/div[2]/div[{coin}]') # перебор элементов выпадающего списка
|
coin = random.randint(3, 24)
|
||||||
variants_list.click()
|
variants_list = form.find_element_by_xpath(
|
||||||
time.sleep(3)
|
f'//*[@id="mG61Hd"]/div/div/div[2]/div[5]/div/div[2]/div[2]/div[{coin}]') # перебор элементов выпадающего списка
|
||||||
|
variants_list.click()
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
elif header == 'Укажите Ваш стаж работы (полных лет) в указанной организации':
|
elif header == 'Укажите Ваш стаж работы (полных лет) в указанной организации':
|
||||||
buttons_list = form.find_elements_by_class_name('appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
buttons_list = form.find_elements_by_class_name(
|
||||||
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||||
|
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
||||||
|
|
||||||
elif header == 'Укажите тип Вашей должности':
|
elif header == 'Укажите тип Вашей должности':
|
||||||
buttons_list = form.find_elements_by_class_name('appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
buttons_list = form.find_elements_by_class_name(
|
||||||
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||||
|
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
||||||
|
|
||||||
elif header == 'Укажите название Вашей должности':
|
elif header == 'Укажите название Вашей должности':
|
||||||
field = form.find_elements_by_class_name('quantumWizTextinputPapertextareaInput')[0] # получение полей для ввода с формы
|
field = form.find_elements_by_class_name('quantumWizTextinputPapertextareaInput')[
|
||||||
field.click()
|
0] # получение полей для ввода с формы
|
||||||
field.send_keys(get_profession())
|
field.click()
|
||||||
|
field.send_keys(get_profession())
|
||||||
|
|
||||||
elif header == 'Укажите Ваш стаж работы в текущей должности (полных лет)':
|
elif header == 'Укажите Ваш стаж работы в текущей должности (полных лет)':
|
||||||
buttons_list = form.find_elements_by_class_name('appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
buttons_list = form.find_elements_by_class_name(
|
||||||
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||||
|
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
||||||
|
|
||||||
|
|
||||||
def bulldozer():
|
def bulldozer():
|
||||||
|
|
||||||
forms_list = driver.find_elements_by_class_name('freebirdFormviewerViewItemsItemItem') # получение форм со страницы
|
forms_list = driver.find_elements_by_class_name(
|
||||||
for form in forms_list:
|
'freebirdFormviewerViewItemsItemItem') # получение форм со страницы
|
||||||
header = form.find_element_by_class_name('freebirdFormviewerViewItemsItemItemHeader').text # получение заголовка формы
|
for form in forms_list:
|
||||||
if header[-1:] == '*':
|
header = form.find_element_by_class_name(
|
||||||
header = header[:-2]
|
'freebirdFormviewerViewItemsItemItemHeader').text # получение заголовка формы
|
||||||
|
if header[-1:] == '*':
|
||||||
|
header = header[:-2]
|
||||||
|
|
||||||
buttons_list = form.find_elements_by_class_name('appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
buttons_list = form.find_elements_by_class_name(
|
||||||
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||||
|
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
url = 'https://docs.google.com/forms/d/1f716YOLUrKhtjTlR4hYiEWkgwjqylR5fCPxWsHQKJqY'
|
url = 'https://docs.google.com/forms/d/1f716YOLUrKhtjTlR4hYiEWkgwjqylR5fCPxWsHQKJqY'
|
||||||
resnondents = int(input('Введите желаемое число респондентов: '))
|
resnondents = int(input('Введите желаемое число респондентов: '))
|
||||||
|
|
||||||
|
driver = webdriver.Firefox()
|
||||||
|
|
||||||
driver = webdriver.Firefox()
|
with progressbar.ProgressBar(max_value=resnondents) as bar:
|
||||||
|
for i in range(resnondents):
|
||||||
|
|
||||||
with progressbar.ProgressBar(max_value=resnondents) as bar:
|
bar.update(i)
|
||||||
for i in range(resnondents):
|
|
||||||
|
|
||||||
bar.update(i)
|
driver.get(url)
|
||||||
|
|
||||||
driver.get(url)
|
button_by_text('Далее')
|
||||||
|
|
||||||
button_by_text('Далее')
|
|
||||||
|
|
||||||
profile_maker()
|
|
||||||
|
|
||||||
button_by_text('Далее')
|
|
||||||
|
|
||||||
bulldozer()
|
|
||||||
|
|
||||||
button_by_text('Далее')
|
|
||||||
|
|
||||||
bulldozer()
|
|
||||||
|
|
||||||
button_by_text('Далее')
|
|
||||||
|
|
||||||
button_by_text('Отправить')
|
|
||||||
|
|
||||||
driver.close()
|
|
||||||
|
|
||||||
|
profile_maker()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
if button_by_text('Далее'):
|
||||||
|
bulldozer()
|
||||||
|
else:
|
||||||
|
button_by_text('Отправить')
|
||||||
|
|
||||||
|
driver.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user