Skip to content

Commit

Permalink
Refactor code to use string parameter instead of text parameter in Be…
Browse files Browse the repository at this point in the history
…autifulSoup find method
  • Loading branch information
TheLime1 committed Feb 16, 2024
1 parent bb1333e commit 1118386
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions esprit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def get_student_name(self):
response = self.session.get(self.url)
soup = BeautifulSoup(response.text, 'html.parser')

# Check if the <p> tag with the class "lead" and the text "Vous pouvez consulter dans cet espace :" exists
# Check if the <p> tag with the class "lead" and the string "Vous pouvez consulter dans cet espace :" exists
p_tag = soup.find('p', class_='lead',
text='Vous pouvez consulter dans cet espace :')
string='Vous pouvez consulter dans cet espace :')
if p_tag is None:
print("The page does not contain the expected text.")
return None
Expand All @@ -43,15 +43,14 @@ def get_student_class(self):
response = self.session.get(self.url)
soup = BeautifulSoup(response.text, 'html.parser')

# Check if the <p> tag with the class "lead" and the text "Vous pouvez consulter dans cet espace :" exists
# Check if the <p> tag with the class "lead" and the string "Vous pouvez consulter dans cet espace :" exists
p_tag = soup.find('p', class_='lead',
text='Vous pouvez consulter dans cet espace :')
string='Vous pouvez consulter dans cet espace :')
if p_tag is None:
print("The page does not contain the expected text.")
return None

span = soup.find(
'span', {'id': 'Label3', 'style': 'color:#CC0000;font-weight:bold;'})
span = soup.find('span', {'id': 'Label3'})
if span is not None:
return span.text.strip()
else:
Expand Down

0 comments on commit 1118386

Please sign in to comment.