Spaces:
Paused
Paused
| import requests | |
| from bs4 import BeautifulSoup | |
| def get_q_paper(ccode): | |
| files = { | |
| 'ccode': (None, ccode), | |
| 'submit': (None, ''), | |
| } | |
| response = requests.post('https://cl.thapar.edu/view1.php', files=files,verify=False) | |
| return extract_question_papers(response.text) | |
| def extract_question_papers(html_content): | |
| soup = BeautifulSoup(html_content, 'html.parser') | |
| table = soup.find('table', {'border': '1'}) # Find the table with question papers | |
| rows = table.find_all('tr')[2:] # Skip the header rows | |
| question_papers = [] | |
| for row in rows: | |
| columns = row.find_all('td') | |
| if len(columns) == 6: # Ensure it's a valid row with 6 columns | |
| course_code = columns[0].text.strip() | |
| course_name = columns[1].text.strip() | |
| year = columns[2].text.strip() | |
| semester = columns[3].text.strip() | |
| exam_type = columns[4].text.strip() | |
| download_link = columns[5].find('a')['href'].strip() | |
| question_papers.append({ | |
| 'CourseCode': course_code, | |
| 'CourseName': course_name, | |
| 'Year': year, | |
| 'Semester': semester, | |
| 'ExamType': exam_type, | |
| 'DownloadLink': "https://cl.thapar.edu/" + download_link, | |
| }) | |
| return question_papers | |
| # Example usage | |
| if __name__ == "__main__": | |
| result = get_q_paper("UCS414") | |
| print(result) | |