forked from Skryptonyte/MITExamScrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqpysearch.py
More file actions
85 lines (62 loc) · 2.79 KB
/
qpysearch.py
File metadata and controls
85 lines (62 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import threading
import time
import tkinter as tk
from selenium import webdriver
from selenium.webdriver.common.by import By
subject_name = ""
driver = None
root = tk.Tk()
root.geometry("850x400")
root.title("QPSearch")
def on_submit():
global subject_name, driver
subject_name = subject_entry.get()
driver = webdriver.Chrome()
driver.get("https://libportal.manipal.edu/MIT/Question%20Paper.aspx")
thread = threading.Thread(target=traverse)
thread.start()
print(subject_name)
def traverse():
web_table = {}
tbody = driver.find_element(By.ID, 'ctl00_ctl00_chmain_MITContent_FileGridCS_gvFiles').find_element(By.TAG_NAME,
'tbody')
for ele in tbody.find_elements(By.TAG_NAME, 'tr'):
try:
link = ele.find_element(By.TAG_NAME, 'td').find_element(By.TAG_NAME, 'a')
web_table[link.get_attribute('id')] = link.text
except Exception:
pass
for ele_id in web_table:
if '..' in web_table[ele_id]:
pass
elif len(web_table[ele_id]) == 0:
dummyElement = driver.find_element(By.ID, ele_id)
trueElement = dummyElement.find_element(By.XPATH, '..').find_element(By.CSS_SELECTOR, "a[target='_blank']")
if subject_name.lower() in trueElement.text.lower(): # and any(year in trueElement.text.lower() for year in ['2006', '2019']):
print("Found file:", trueElement.get_attribute('href'))
text_widget.insert(tk.END, trueElement.get_attribute('href') + "\n\n")
else:
continue
else:
if any(year in web_table[ele_id] for year in ['2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017']):
continue
else:
driver.find_element(By.ID, ele_id).click()
traverse()
driver.back()
time.sleep(1)
label = tk.Label(root, text="Enter Subject Name/Subject Code:")
label.place(relx=0.5, rely=0.1, anchor='center')
label = tk.Label(root, text="Copy/Paste the links below to view the PDFs:")
label.place(relx=0.5, rely=0.5, anchor='center')
text_widget = tk.Text(root, width=100, height=10)
text_widget.place(relx=0.5, rely=0.8, anchor='center')
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
text_widget.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=text_widget.yview)
subject_entry = tk.Entry(root)
subject_entry.place(relx=0.5, rely=0.2, anchor='center')
submit_button = tk.Button(root, text="Submit", command=on_submit)
submit_button.place(relx=0.5, rely=0.3, anchor='center')
root.mainloop()