Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2adc60e

Browse files
committed
examples without the pre tag
1 parent 2b76e81 commit 2adc60e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎leetcode_scraper.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ def _process_problem_data(self, question):
141141
break
142142
prev = prev.previous_element
143143
examples.append(example_dict)
144+
145+
# Fallback: if no <pre> examples found, try <div class="example-block">
146+
if not examples:
147+
example_blocks = soup.find_all('div', class_='example-block')
148+
for i, block in enumerate(example_blocks, 1):
149+
# Collect all <p> tags inside the block
150+
block_texts = []
151+
for p in block.find_all('p'):
152+
block_texts.append(p.get_text(separator=' ', strip=True))
153+
example_text = '\n'.join(block_texts)
154+
# Find images inside the block
155+
images = [img['src'] for img in block.find_all('img') if img.has_attr('src')]
156+
example_dict = {
157+
'example_num': i,
158+
'example_text': example_text,
159+
'images': images
160+
}
161+
examples.append(example_dict)
144162
problem_data['examples'] = examples
145163

146164
# Extract constraints

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /