bastostam 1
bastostam 1

Reputation: 75

Get text from site using python

I'm trying to get the question number text from kahoot site (https://kahoot.it/challenge/15a3e9c2-65fe-4cb2-9441-a4023ed0e69e_1590141953862)

This is my code:

url='https://kahoot.it/challenge/15a3e9c2-65fe-4cb2-9441-a4023ed0e69e_1590141953862'
import requests
from bs4 import BeautifulSoup
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
page_content = soup.find(class_='kahoot-title__Host-sc-1t7km5t-8 dVORBp')
artist_name_list_items = page_content.find_all('span')
print(artist_name_list_items)

When I run this I get this error message: AttributeError: 'NoneType' object has no attribute 'find_all'

Upvotes: 1

Views: 57

Answers (1)

9 Guy
9 Guy

Reputation: 309

The error is because BeautifulSoup can't find an html element with the class 'kahoot-title__Host-sc-1t7km5t-8 dVORBp', and neither can I, unless I load JS within the browser.

Bs4 is usually used on static websites, and kahoot mostly uses javascript to serve content. You may be better off using a controlled browser like Selenium

Upvotes: 1

Related Questions