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 2b76e81

Browse files
committed
follow ups fixed
1 parent bc1d944 commit 2b76e81

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

‎leetcode_scraper.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,20 @@ def _process_problem_data(self, question):
162162

163163
# Extract follow-up section if it exists
164164
follow_ups = []
165-
for elem in soup.find_all(['p', 'strong']):
166-
if elem.name == 'strong' and 'Follow-up' in elem.text:
167-
follow_up_text = elem.parent.get_text().strip()
168-
follow_ups.append(follow_up_text)
169-
170-
# Sometimes follow-ups are in paragraphs after the header
171-
next_elem = elem.parent.next_sibling
172-
while next_elem and next_elem.name == 'p':
173-
follow_up_text = next_elem.get_text().strip()
174-
if follow_up_text:
175-
follow_ups.append(follow_up_text)
165+
for p in soup.find_all('p'):
166+
strong = p.find('strong')
167+
if strong and 'Follow up' in strong.get_text():
168+
# Get the text after <strong> in the same <p>
169+
follow_up_text = p.get_text().replace(strong.get_text(), '').strip()
170+
if follow_up_text:
171+
follow_ups.append(follow_up_text)
172+
# Also check next <p> tags for additional follow-up info
173+
next_elem = p.next_sibling
174+
while next_elem and getattr(next_elem, 'name', None) == 'p':
175+
extra_text = next_elem.get_text().strip()
176+
if extra_text:
177+
follow_ups.append(extra_text)
176178
next_elem = next_elem.next_sibling
177-
178179
problem_data['follow_ups'] = follow_ups
179180

180181
# Extract hints from the API response
@@ -241,7 +242,7 @@ def scrape_problem_list(self, limit=10):
241242

242243
if __name__ == "__main__":
243244
scraper = LeetCodeScraper()
244-
problem_data = scraper.scrape_problem("linked-list-cycle")
245+
problem_data = scraper.scrape_problem("longest-strictly-increasing-or-strictly-decreasing-subarray")
245246
print(json.dumps(problem_data, indent=2))
246247
# Option 2: Scrape multiple problems from the list
247248
# problem_list = scraper.scrape_problem_list(limit=5)

0 commit comments

Comments
(0)

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