Код: Выделить всё
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import openpyxl
# put in spreadsheet
df = pd.read_excel('1000 of the most common Spanish Nouns.xlsx')
# Type in your email or username
email = 'email'
password = 'password'
folder_name = input('Folder Name: ')
quiz_question_length = int(input('Length of each quiz: '))
# set up the webdriver
driver = webdriver.Chrome()
# go to kahoot login
driver.get('https://create.kahoot.it/auth/login')
# type kahoot account credentials
driver.implicitly_wait(10)
driver.find_element(By.ID, 'username').send_keys(f"{email}")
driver.find_element(By.ID, 'password').send_keys(f"{password}")
# get rid of potential popup
try:
driver.find_element(By.CSS_SELECTOR, 'button[id="onetrust-pc-btn-handler"]').click()
driver.find_element(By.CSS_SELECTOR, 'button[class="ot-pc-refuse-all-handler"]').click()
print('skipped cookie popup')
except:
print('no cookie popup')
# press login
driver.find_element(By.CSS_SELECTOR, 'button[id="login-submit-btn"]').click()
WebDriverWait(driver, 30).until(EC.url_contains("create.kahoot.it"))
# skip second popup
try:
driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Next"]').click()
driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Next"]').click()
driver.find_element(By.CSS_SELECTOR, 'a[class="btn btn--text"]').click()
print('skipped second popup')
except:
print('no second popup')
# go to kahoot account's library
driver.implicitly_wait(10)
driver.find_element(By.CSS_SELECTOR, 'a[data-functional-selector="side-bar-link__library"]').click()
# create a new folder for kahoot quiz
driver.find_element(By.CSS_SELECTOR, 'button[data-functional-selector="library_side-bar_create-folder"]').click()
driver.find_element(By.CSS_SELECTOR, 'input[placeholder="New folder"]').send_keys(f'{folder_name}', Keys.ENTER)
# split df into multiple different parts
quizzes = []
for i in range(0, len(df), quiz_question_length):
if i + quiz_question_length < len(df) + 1:
quizzes.append(df.iloc[i:i + quiz_question_length])
else:
quizzes.append(df.iloc[i:])
# begin creating quizzes
for quiz in quizzes:
# create new kahoot quiz
driver.implicitly_wait(10)
driver.find_element(By.CSS_SELECTOR,
'button[class="button__Button-sc-c6mvr2-0 iwRYhY create-button__PrimaryButton-sc-1wmq7f8-0 jaZrfx"]').click()
driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Create new Kahoot."]').click()
# choose blank option for kahoot quiz
driver.find_element(By.CSS_SELECTOR, 'button[class="styles__FlowOptionInnerContainer-sc-hcxgxq-2 gmFgAG"]').click()
driver.find_element(By.CSS_SELECTOR, 'button[class="flat-button__FlatButton-sc-6uljam-0 iEWtrJ"]').click()
# close the theme panel
driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Close Themes panel"]').click()
# PROBLEM WITH ADDING A NEW TYPE ANSWER QUESTION
for index, row in quiz.iterrows():
# add new answer type question
driver.implicitly_wait(5)
add_question_btn = driver.find_element(By.CSS_SELECTOR, 'button[data-functional-selector="add-question-button"]')
add_question_btn.click()
answer_type_btn = driver.find_element(By.CSS_SELECTOR, 'button[data-functional-selector="create-button__open-ended"]')
answer_type_btn.click()
# set up question and answer input from spreadsheet
question_input = row['Question']
answer_input = row['Answer']
# PROBLEM WITH ADDING QUESTION AND ANSWER TEXT TO QUESTION
question_text = driver.find_element(By.CSS_SELECTOR, 'p[data-placeholder="Start typing your question"]')
question_text.send_keys(question_input)
answer_text = driver.find_element(By.CSS_SELECTOR, 'input[placeholder="Type an answer"]')
answer_text.send_keys(answer_input)
```
df = {
'Question': ['la explosión', 'el apellido', 'la conferencia', 'la intensidad', 'el paquete'],
'Answer': ['explosion', 'last name', 'conference', 'intensity', 'package']
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... ating-a-ka