import requests
from bs4 import BeautifulSoup
url = "https://codeforces.net/problemset/page/11?tags=binary+search"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
questions = soup.find_all('div', class_='problem-statement')
question_texts = [q.find('div', class_='title').text for q in questions]
total_questions = len(question_texts)
first_five_words = [q.split()[:5] for q in question_texts[:5]]
last_five_words = [q.split()[:5] for q in question_texts[-5:]]
print("Total questions:", total_questions)
print("First 5 words of the first question:", first_five_words)
print("First 5 words of the last 5 questions:", last_five_words)
I know this code isn't working bcoz its web scrapping, can anyone tell me how do I use Codeforces API for the same? To fetch all the questions under binary search and store them as a Python list. I am doing this for a Project where I have to train a Transformer model over Programming Problem Statements.