Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue no #928 : Scraping data from geeksforgeeks #936

Merged
merged 7 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/scrape_up/geeksforgeeks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .geeksforgeeks import Geeksforgeeks

__all__ = ["Geeksforgeeks"]
74 changes: 74 additions & 0 deletions src/scrape_up/geeksforgeeks/geeksforgeeks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import requests
import json
from bs4 import BeautifulSoup

class Geeksforgeeks:


"""
Create an instance of the class `GeeksforGeeks`


| Methods | Details |
| ----------------- | ---------------------------------------------------------------------------------- |
| `.get_profile()` | Returns the user data in json format. |


output:
{
"username": "22cs3iehq",
"collage_name": "Rajiv Gandhi Institute of Petroleum Technology (RGIPT) Rae Bareli",
"collage_rank": "1",
"score": {
"overall_coding_score": "6085",
"monthly_coding_score": "14"
},
"languages_used": "C++, Javascript, Python, Java, C",
"current_potd_streak": "407/1015",
"total_problem_solved": "1534",
"campus_ambassader": "22cs3iehq"
}

"""

def __init__(self,user):
self.user = user

def get_profile(self):
try:
url = f"https://www.geeksforgeeks.org/user/{self.user}/"
headers = {"User-Agent": "scrapeup"}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, "html.parser")
main_info=soup.find('div',class_="AuthLayout_head_content__ql3r2")
user_data=[]

username=main_info.find('div',class_="profilePicSection_head_userHandleAndFollowBtnContainer_userHandle__p7sDO").text
collage_rank=main_info.find('span',class_="profilePicSection_head_userRankContainer_rank__abngM").text
collage=main_info.find('div',class_="educationDetails_head_left--text__tgi9I").text
languages=main_info.find('div',class_="educationDetails_head_right--text__lLOHI").text
campus_ambaasder=soup.find('a',class_="basicUserDetails_head_CA--text__IoHEU").text
current_potd_streak=main_info.find('div',class_="circularProgressBar_head_mid_streakCnt__MFOF1 tooltipped").text
score=main_info.find_all('div',class_="scoreCard_head_card_left--score__pC6ZA")
overall_coding_score=score[0].text
total_problem_solved=score[1].text
monthly_coding_score=score[2].text

user_data={
'username':username,
'collage_name':collage,
'collage_rank':collage_rank,
'score':{
'overall_coding_score':overall_coding_score,
'monthly_coding_score':monthly_coding_score,
},
'languages_used':languages,
'current_potd_streak':current_potd_streak,
'total_problem_solved':total_problem_solved,
'campus_ambassader':campus_ambaasder,
}

return json.dumps(user_data)
except:
return None