Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[service: codeforces] ignore NavigableString from tag.children while … #728

Merged
merged 1 commit into from
Apr 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions onlinejudge/service/codeforces.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ def download_sample_cases(self, *, session: Optional[requests.Session] = None) -
samples = onlinejudge._implementation.testcase_zipper.SampleZipper()
for tag in soup.find_all('div', class_=re.compile('^(in|out)put$')): # Codeforces writes very nice HTML :)
log.debug('tag: %s', str(tag))
assert len(list(tag.children)) == 2 # if not 2, next line throws ValueError.
title, pre = list(tag.children)
non_empty_children = [child for child in tag.children if type(child) is not bs4.element.NavigableString]
log.debug("tags after removing bs4.element.NavigableString: %s", non_empty_children)
assert len(non_empty_children) == 2 # if not 2, next line throws ValueError.
title, pre = list(non_empty_children)
assert 'title' in title.attrs['class']
assert pre.name == 'pre'
s = utils.parse_content(pre)
Expand Down