@@ -162,19 +162,20 @@ def _process_problem_data(self, question):
162
162
163
163
# Extract follow-up section if it exists
164
164
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 )
176
178
next_elem = next_elem .next_sibling
177
-
178
179
problem_data ['follow_ups' ] = follow_ups
179
180
180
181
# Extract hints from the API response
@@ -241,7 +242,7 @@ def scrape_problem_list(self, limit=10):
241
242
242
243
if __name__ == "__main__" :
243
244
scraper = LeetCodeScraper ()
244
- problem_data = scraper .scrape_problem ("linked-list-cycle " )
245
+ problem_data = scraper .scrape_problem ("longest-strictly-increasing-or-strictly-decreasing-subarray " )
245
246
print (json .dumps (problem_data , indent = 2 ))
246
247
# Option 2: Scrape multiple problems from the list
247
248
# problem_list = scraper.scrape_problem_list(limit=5)
0 commit comments