0% found this document useful (0 votes)
8 views2 pages

New Text Document - Py

The document contains a Python script that fetches student results from a specified URL using the requests library and parses the HTML content with BeautifulSoup. It extracts student names, departments, and results from a table in the HTML. The script iterates over a range of seat numbers to collect data and store it in a structured format.

Uploaded by

gnfgnn60
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

New Text Document - Py

The document contains a Python script that fetches student results from a specified URL using the requests library and parses the HTML content with BeautifulSoup. It extracts student names, departments, and results from a table in the HTML. The script iterates over a range of seat numbers to collect data and store it in a structured format.

Uploaded by

gnfgnn60
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import requests

from bs4 import BeautifulSoup


import pandas as pd
import time

BASE_URL = "https://ae-online-courses-academy.com/result/azharia_results"

def extract_student_data(html_content):
soup = BeautifulSoup(html_content, 'html.parser')

# Check if result section exists


result_section = soup.find(id="result-section")
if not result_section:
return None

# Extract student name


student_name_span = result_section.select_one(".student-info span")
student_name = student_name_span.text.strip() if student_name_span else None

# Extract department
student_dept_span = result_section.select_one(".student-dept span")
student_dept = student_dept_span.text.strip() if student_dept_span else None

# Extract table data


table = result_section.find("table", id="result-table")
if not table:
return None

data = {
"‫"االسم‬: student_name,
"‫"القسم‬: student_dept
}

rows = table.find_all("tr")
for row in rows:
cols = row.find_all("td")
if len(cols) >= 2:
key = cols[0].text.strip()
val = cols[1].text.strip()
data[key] = val

return data

def main():
all_results = []
start_seat = 1000
end_seat = 1050 # Change to your max range

for seat_num in range(start_seat, end_seat + 1):


seat_str = str(seat_num)
print(f"Fetching data for seat number: {seat_str}")

payload = {
"seat_number": seat_str,
"view_mode": "azharia"
}

try:
response = requests.post(BASE_URL, data=payload)
if response.status_code == 200:
student_data = extract_student_data(response.text_

You might also like