Description
The script crashes with a TypeError when it reaches the last page of dependencies because next_url becomes None but the code tries to access next_url['href'] without checking.
Steps to Reproduce
- Run the script against an organization with few dependencies
- The script iterates through pages until there is no "next" link
- On the last page,
soup.select_one("a[href*=after]") returns None
- Code tries to access
next_url['href'] on None, causing crash
Expected Behavior
The script should gracefully exit the loop when there are no more pages, or handle the None case appropriately.
Actual Behavior
TypeError: 'NoneType' object is not subscriptable
Code Location
next_url = soup.select_one("a[href*=after]")
# Missing check: if next_url is None: break
print(next_url['href'])
return next_url['href']
Suggested Fix
next_url = soup.select_one("a[href*=after]")
if next_url is None:
return None # Signal end of pagination
return next_url['href']
And update the main loop:
while iterations > 1:
result = get_dependencies_for_url(current_url, cookies)
if result is None:
break
current_url = result
iterations -= 1
This would also eliminate the need for the hardcoded iterations = 313 value.
Description
The script crashes with a
TypeErrorwhen it reaches the last page of dependencies becausenext_urlbecomesNonebut the code tries to accessnext_url['href']without checking.Steps to Reproduce
soup.select_one("a[href*=after]")returnsNonenext_url['href']onNone, causing crashExpected Behavior
The script should gracefully exit the loop when there are no more pages, or handle the
Nonecase appropriately.Actual Behavior
Code Location
Suggested Fix
And update the main loop:
This would also eliminate the need for the hardcoded
iterations = 313value.