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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
||||
./vscode
|
||||
./geckodriver.log
|
||||
./draft.txt
|
||||
./respondents.log
|
||||
82
__init__.py
82
__init__.py
@@ -8,7 +8,11 @@ from os import path
|
||||
from bs4 import BeautifulSoup
|
||||
from datetime import datetime
|
||||
|
||||
global driver, banList
|
||||
options = webdriver.firefox.options.Options()
|
||||
options.headless = True
|
||||
driver = webdriver.Firefox(options=options)
|
||||
|
||||
logPath = './respondents.log'
|
||||
|
||||
banList = []
|
||||
if path.exists('./ban_list.txt'):
|
||||
@@ -36,6 +40,15 @@ if path.exists('./weights_list.txt'):
|
||||
f.close()
|
||||
|
||||
|
||||
def log(header, data=None):
|
||||
with open(logPath,'a') as f:
|
||||
f.write(datetime.now().strftime('[%X] ') + header +'\n')
|
||||
if data:
|
||||
for key, value in data.items():
|
||||
f.write(f' {key}: {value}\n')
|
||||
f.write('\n')
|
||||
|
||||
|
||||
def button_by_text(text): # получение кнопки по тексту на ней
|
||||
|
||||
try:
|
||||
@@ -95,6 +108,8 @@ def profile_maker():
|
||||
|
||||
global driver
|
||||
|
||||
profile = {}
|
||||
|
||||
forms_list = driver.find_elements_by_class_name(
|
||||
'freebirdFormviewerViewItemsItemItem') # получение форм со страницы
|
||||
for form in forms_list:
|
||||
@@ -107,10 +122,12 @@ def profile_maker():
|
||||
|
||||
if header == 'Укажите Ваш пол':
|
||||
buttons_list = form.find_elements_by_class_name(
|
||||
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||
'docssharedWizToggleLabeledContainer') # получение кнопок-радио с формы
|
||||
button = random.choices(buttons_list, [0.7, 0.3], k=1)[0]
|
||||
button.click()
|
||||
|
||||
profile['Пол'] = button.text
|
||||
|
||||
elif header == 'Укажите Ваш возраст (полных лет)':
|
||||
age = random.randint(18, 56)
|
||||
field = form.find_elements_by_class_name('quantumWizTextinputPaperinputInput')[
|
||||
@@ -118,42 +135,64 @@ def profile_maker():
|
||||
field.click()
|
||||
field.send_keys(age)
|
||||
|
||||
profile['Возраст'] = age
|
||||
|
||||
elif header == 'Укажите Ваше образование (возможно несколько вариантов)':
|
||||
buttons_list = form.find_elements_by_class_name(
|
||||
'quantumWizTogglePapercheckboxEl') # получение чекбоксов с формы
|
||||
buttons_list[random.randint(0, 4)].click()
|
||||
'docssharedWizToggleLabeledContainer') # получение чекбоксов с формы
|
||||
coin = random.randint(0, 4)
|
||||
buttons_list[coin].click()
|
||||
|
||||
profile['Образование'] = buttons_list[coin].text
|
||||
|
||||
elif header == 'Выберите из списка основную сферу деятельности организации, в которой Вы сейчас работаете':
|
||||
form.find_elements_by_class_name(
|
||||
'quantumWizMenuPaperselectOption')[0].click()
|
||||
coin = random.randint(3, 24)
|
||||
time.sleep(1)
|
||||
variants_list = form.find_element_by_xpath(
|
||||
f'//*[@id="mG61Hd"]/div/div/div[2]/div[5]/div/div[2]/div[2]/div[{coin}]') # перебор элементов выпадающего списка
|
||||
variants_list.click()
|
||||
time.sleep(0.5)
|
||||
variant = form.find_element_by_xpath(
|
||||
f'/html/body/div/div[2]/form/div/div/div[2]/div[5]/div/div[2]/div[2]/div[{coin}]') # перебор элементов выпадающего списка
|
||||
|
||||
profile['Сфера'] = variant.text
|
||||
|
||||
variant.click()
|
||||
time.sleep(1.5)
|
||||
|
||||
elif header == 'Укажите Ваш стаж работы (полных лет) в указанной организации':
|
||||
buttons_list = form.find_elements_by_class_name(
|
||||
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
||||
'docssharedWizToggleLabeledContainer') # получение кнопок-радио с формы
|
||||
coin = random.randint(0, len(buttons_list) - 1)
|
||||
buttons_list[coin].click()
|
||||
|
||||
profile['Стаж работы'] = buttons_list[coin].text
|
||||
|
||||
elif header == 'Укажите тип Вашей должности':
|
||||
buttons_list = form.find_elements_by_class_name(
|
||||
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
||||
'docssharedWizToggleLabeledContainer') # получение кнопок-радио с формы
|
||||
coin = random.randint(0, len(buttons_list) - 1)
|
||||
buttons_list[coin].click()
|
||||
|
||||
profile['Тип должности'] = buttons_list[coin].text
|
||||
|
||||
elif header == 'Укажите название Вашей должности':
|
||||
field = form.find_elements_by_class_name('quantumWizTextinputPapertextareaInput')[
|
||||
0] # получение полей для ввода с формы
|
||||
field.click()
|
||||
# field.send_keys(random.choice(professionsList))
|
||||
field.send_keys(get_profession())
|
||||
profession = get_profession()
|
||||
field.send_keys(profession)
|
||||
|
||||
profile['Должность'] = profession
|
||||
|
||||
elif header == 'Укажите Ваш стаж работы в текущей должности (полных лет)':
|
||||
buttons_list = form.find_elements_by_class_name(
|
||||
'appsMaterialWizToggleRadiogroupRadioButtonContainer') # получение кнопок-радио с формы
|
||||
buttons_list[random.randint(0, len(buttons_list) - 1)].click()
|
||||
'docssharedWizToggleLabeledContainer') # получение кнопок-радио с формы
|
||||
coin = random.randint(0, len(buttons_list) - 1)
|
||||
buttons_list[coin].click()
|
||||
|
||||
profile['Стаж в текущей должности'] = buttons_list[coin].text
|
||||
|
||||
log('Новорожденный', profile)
|
||||
|
||||
|
||||
def smart_buildozer():
|
||||
@@ -200,11 +239,9 @@ def main():
|
||||
respondents = int(input(datetime.now().strftime(
|
||||
'[%X] ') + 'Введите желаемое число респондентов: '))
|
||||
|
||||
options = webdriver.firefox.options.Options()
|
||||
options.headless = True
|
||||
driver = webdriver.Firefox(options=options)
|
||||
print(datetime.now().strftime('[%X] ') + 'Начало')
|
||||
|
||||
print(datetime.now().strftime('[%X] ') + 'Начато')
|
||||
log('Новый опрос')
|
||||
|
||||
with progressbar.ProgressBar(max_value=respondents) as bar:
|
||||
for i in range(respondents):
|
||||
@@ -222,6 +259,8 @@ def main():
|
||||
button_by_text('Отправить')
|
||||
break
|
||||
|
||||
log('Опрошен')
|
||||
|
||||
driver.close()
|
||||
|
||||
print(datetime.now().strftime('[%X] ') + 'Завершено')
|
||||
@@ -229,8 +268,11 @@ def main():
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
'''
|
||||
try:
|
||||
main()
|
||||
exec Exeption:
|
||||
except:
|
||||
driver.close()
|
||||
'''
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user