Error while trying to get the text of a div

Viewed 310

I'm trying to get the html/text inside of a div. The div has a class of math.

This is the code I used:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import time
    from bs4 import BeautifulSoup as soup
    from bs4 import SoupStrainer
    import urllib.request
    from selenium.webdriver.common.action_chains import ActionChains
    import getpass

    ui = input('What is your IXL username?\n\n')
    pi = getpass.getpass('\nWhat is your IXL password?\n\n')

    driver = 'C:\\Users\\agzsc\\Desktop\\MicrosoftWebDriver.exe'
    driver = webdriver.Edge(driver)
    driver.get('https://www.ixl.com')
    username = driver.find_element_by_id('qlusername')
    password = driver.find_element_by_id('qlpassword')
    submit = driver.find_element_by_id('qlsubmit')
    username.send_keys(ui)
    password.send_keys(pi)
    ActionChains(driver).move_to_element(submit).click().perform()

    for x in range(1):
        time.sleep(1)
        driver.execute_script('''window.open("https://www.ixl.com/math/grade-3/multiply-by-11","_blank");''')
        driver.switch_to_window(driver.window_handles[1+x])
        math = soup.find_all('div', attrs={"class":"math"})
        print(math)

As you can see, I am using selenium webdriver for Microsoft Edge. I am also trying to parse the page with bs4 and only get the div with the class math. However, I keep getting this error:

    Traceback (most recent call last):
  File "C:\Users\agzsc\Downloads\powerixl.py", line 41, in <module>
    math = soup.find_all('div', attrs={"class":"math"})
  File "C:\Users\agzsc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bs4\element.py", line 1310, in find_all
    generator = self.descendants
AttributeError: 'str' object has no attribute 'descendants'

If anyone can help, I will be very gracious. Thanks!

1 Answers
Related