-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (32 loc) · 1.05 KB
/
main.py
File metadata and controls
39 lines (32 loc) · 1.05 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
from bs4 import BeautifulSoup
def scrape(page):
"""
it takes html code of Vjudge contest on your local machine
anlyze it and extract all problem set
:param page:
:return:
"""
soup = BeautifulSoup(page, 'html.parser')
tabelList = soup.find_all('a', target='_blank')
problemSet = []
for i in tabelList:
ss = i.get_text(strip=True)
if len(ss.split()) == 2:
problemSet.append(ss)
return problemSet
HtmlFilePath = input("Enter the path of the Html File:")
HtmlFile = open(HtmlFilePath, 'r')
try:
with open(HtmlFilePath, "r",encoding="utf-8") as HtmlFile:
PageContent = HtmlFile.read()
listOfProblems = scrape(PageContent)
for problem in listOfProblems:
Judge, id = problem.split()
print(Judge, "\t|\t", id, "\t|\t1\t|")
HtmlFile.close()
except FileNotFoundError:
print("File not found.")
except PermissionError:
print("Permission denied.")
except Exception as e:
print("An error occurred:", e)