Created
March 19, 2024 14:53
-
-
Save philipsinnott/7b6fe6943aec6b38d4611116e0a7fb37 to your computer and use it in GitHub Desktop.
Extract endpoints from a list of urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/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