Skip to content

Commit

Permalink
Made minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhil25803 committed May 14, 2024
1 parent 6ee6158 commit 6e8ed3c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/scrape_up/geeksforgeeks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .geeksforgeeks import Geeksforgeeks

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

class Geeksforgeeks:


class Geeksforgeeks:
"""
Create an instance of the class `GeeksforGeeks`
```py
gfg = Geeksforgeeks(user="nikhil25803")
gfg.get_profile()
```
| Methods | Details |
| ----------------- | ---------------------------------------------------------------------------------- |
| `.get_profile()` | Returns the user data in json format. |
output:
Response:
```js
{
"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"
"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):
def __init__(self, user):
self.user = user

def get_profile(self):
Expand All @@ -40,35 +42,53 @@ def get_profile(self):
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=[]
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
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,
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,
"languages_used": languages,
"current_potd_streak": current_potd_streak,
"total_problem_solved": total_problem_solved,
"campus_ambassader": campus_ambaasder,
}

return json.dumps(user_data)
return user_data
except:
return None


gfg = Geeksforgeeks(user="nikhil25803")
print(gfg.get_profile())

0 comments on commit 6e8ed3c

Please sign in to comment.