I have been trying to web scrape the leaderboard of a coding platform named GeeksForGeeks.
The given code should work perfectly fine. But it doesn’t work at all.
import requests
from bs4 import BeautifulSoup
try:
for page in range(1,3):
url = 'https://www.geeksforgeeks.org/colleges/lnct-university/students/?page='+str(page)
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
# Find all user profile divs
user_profile_divs = soup.find_all('div', class_='UserCodingProfileCard_userCodingProfileCard__0GQCR')
for user_profile in user_profile_divs:
# Extract user details
user_name = user_profile.find('p', class_='UserCodingProfileCard_userCodingProfileCard_dataDiv_data--linkhandle__lZchE').text
practice_problem = user_profile.find('p', class_='UserCodingProfileCard_userCodingProfileCard_dataDiv_data--value__3A8Kx').text
coding_score = user_profile.find('p', class_='UserCodingProfileCard_userCodingProfileCard_dataDiv_data--value__3A8Kx').text
potd_streak = user_profile.find('p', class_='UserCodingProfileCard_userCodingProfileCard_dataDiv_data--value__3A8Kx').text
# Print the extracted information
print(f"User Name: {user_name}")
print(f"Practice Problem: {practice_problem}")
print(f"Coding Score: {coding_score}")
print(f"POTD Streak: {potd_streak}")
print("n")
except Exception as e:
print(e)
New contributor
Hardik Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1