Skip to content

Commit

Permalink
fix: page
Browse files Browse the repository at this point in the history
Signed-off-by: Dup4 <[email protected]>
  • Loading branch information
Dup4 committed Jul 21, 2024
1 parent 401a4f6 commit 72a27e0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions origin-data/camp/tsinghua/2024/online-qualification/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def fetch(uri: str) -> str:
return resp.text


def parse_pagination(html: str) -> int:
soup = bs4.BeautifulSoup(html, 'html5lib')
pagination_div = soup.select('.custom-links-pagination')[0]
children = pagination_div.find_all(recursive=False)
return len(children)


def parse_teams(html: str) -> Teams:
teams = Teams()
soup = bs4.BeautifulSoup(html, 'html5lib')
Expand Down Expand Up @@ -171,13 +178,18 @@ def work(c: Contest, data_dir: str, fetch_uri: str):
try:
teams = Teams()
submissions = Submissions()
for i in range(1, 5):
uri = f"{fetch_uri}/groupmates/true/page/{i}"
page = 1
cur_index = 1
while cur_index <= page:
uri = f"{fetch_uri}/groupmates/true/page/{cur_index}"
resp = fetch(uri)
page = parse_pagination(resp)
log.info(f"fetch page {cur_index}/{page}")
_teams = parse_teams(resp)
_submissions = parse_submissions(resp)
teams.update(_teams)
submissions.extend(_submissions)
cur_index += 1
write_to_disk(data_dir, c, teams, submissions)
log.info("work successfully")
except Exception as e:
Expand Down

0 comments on commit 72a27e0

Please sign in to comment.