#đź”’ How to import questions from an Excel file into Copilot, and then return the answers back to Excel

7 messages · Page 1 of 1 (latest)

sly wolf
#

I'm stuck on finding the correct HTML attributes. Here’s the code.

import time
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys

input_file_path = 'random_questions.xlsx'  
output_file_path = 'random_questions.xlsx'  
questions_df = pd.read_excel(input_file_path)

# Use WebDriver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://copilot.microsoft.com/")

answers = []

for question in questions_df['Random Questions']:
    # Clear cache
    driver.delete_all_cookies()
    driver.refresh()

    # Wait for the page to load
    time.sleep(5)

    # Find the input box and enter the question
    try:
        label = driver.find_element(By.CSS_SELECTOR, 'label.text-input[data-input]')
        driver.execute_script("arguments[0].setAttribute('data-input', arguments[1])", label, question)
        
        # Simulate pressing the enter key
        label.send_keys(Keys.RETURN)
    except Exception as e:
        answers.append(f"Error submitting question: {e}")
        continue

    # Wait for the answer to be generated
    time.sleep(10)

    # Retrieve the answer
    try:
        response_elements = driver.find_elements(By.CLASS_NAME, 'textarea#searchbox') 
        answer = " ".join([element.text for element in response_elements])
    except Exception as e:
        answer = f"Error retrieving answer: {e}"

    answers.append(answer)

driver.quit()

# Save results to Excel
questions_df['Answers'] = answers
questions_df.to_excel(output_file_path, index=False)

print(f"Results saved to {output_file_path}")

After running the code below, I got this answer in Excel.
Error submitting question: Message: no such element: Unable to locate element: {"method":"css selector","selector":"label.text-input[data-input]"}

leaden bladeBOT
#

@sly wolf

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sly wolf
#

可以這樣標題:Importing Questions from Excel to Copilot and Exporting Answers Back to Excel

#

Importing Questions from Excel to Copilot and Exporting Answers Back to Excel

#

How to import questions from Excel into Copilot and return the answers to Excel?

leaden bladeBOT
#

@sly wolf

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.