Trying to make a program that gets a random subreddit, displays the title to the terminal, asks the user if they want to see it and if so opens a browser with that subreddit.
I'm running into an issue here whilst doing so. I am very new with python/beautiful soup just started using it a few weeks ago for school any help will be very appreciated.
import requests
from bs4 import BeautifulSoup
import webbrowser
while True:
url = requests.get("https://www.reddit.com/r/random")
soup = BeautifulSoup(url.content, "html.parser")
title = soup.find(class_="_2yYPPW47QxD4lFQTKpfpLQ").text ## this is supposed to get the title of the subreddit and this is where my error is occurring
print(f"{title} \nSelect this subreddit? (Y/N)")
ans = input("").lower()
if ans == "y":
url = "https://www.reddit.com/%s" % title ## Some issue, not sure what
webbrowser.open(url)
break
elif ans == "n":
print("Try again!")
continue
else:
print("Wrong choice!")
break