Need Help for a Python Project I am working on Please Guys

Revision en4, by illuminati_13, 2024-07-24 09:47:33
import requests
from bs4 import BeautifulSoup

url = "https://mirror.codeforces.com/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.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English illuminati_13 2024-07-24 09:48:57 110
en4 English illuminati_13 2024-07-24 09:47:33 5
en3 English illuminati_13 2024-07-24 09:37:20 9 Tiny change: '\n~~~~~\nimp' -> '~~~~~\nimp'
en2 English illuminati_13 2024-07-24 09:32:24 56
en1 English illuminati_13 2024-07-24 09:31:38 963 Initial revision (published)