Skip to content

Instantly share code, notes, and snippets.

@philipsinnott
Created March 19, 2024 14:53
Show Gist options
  • Save philipsinnott/7b6fe6943aec6b38d4611116e0a7fb37 to your computer and use it in GitHub Desktop.
Save philipsinnott/7b6fe6943aec6b38d4611116e0a7fb37 to your computer and use it in GitHub Desktop.
Extract endpoints from a list of urls
# ~/tools/endpointz.py urls.txt | tee endpoints.txt
import sys
from urllib.parse import urlparse
def extract_endpoints(urls):
endpoints = set()
for url in urls:
parsed_url = urlparse(url)
path = parsed_url.path.strip()
if path:
endpoints.add(path)
return endpoints
def main():
urls = sys.stdin.readlines()
endpoints = extract_endpoints(urls)
for endpoint in endpoints:
sys.stdout.write(endpoint + '\n')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment